Perl Syntax
Kevin C. Krinke
kckrinke-eqjHHVKjh9GttCpgsWEBFlaTQe2KTcn/ at public.gmane.org
Mon May 23 21:35:21 UTC 2005
On Mon, 2005-05-23 at 17:10 -0400, John Wildberger wrote:
> Could someone give me an item by item explanation of the following
> perl code line:
> $SIG{INT} = \&do_signal;
> My various books on Perl seem to be short on explanations for this
> type of code.
%SIG which $SIG{INT} is a part of is one of the "magical" things in
Perl. The %SIG hash represents all the different application signals
(ie: kill, term, quit, hup, etc) and what to do when the individual
signals are received.
$SIG{INT} is the INTerrupt signal which is normally associated with
something bad happening that cases the program to exit prematurely.
do_signal is a sub function within the program. The ampersand at the
start of the name indicates this and the backslash prefixing the
ampersand turns that particular function call into a reference to the
function do_signal instead of actually calling the function at that
time. This reference to the do_signal function is assigned to the
$SIG{INT} signal.
Now whenever the program receives the application signal "INT", the
function do_signal will be called because the code reference to the
function do_signal is referenced as the value of the INT key of the
magical %SIG hash.
Did that help?
--
Kevin C. Krinke <kckrinke-eqjHHVKjh9GttCpgsWEBFlaTQe2KTcn/@public.gmane.org>
Open Door Software Inc.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list