Perl Syntax

John Wildberger wildberger-iRg7kjdsKiH3fQ9qLvQP4Q at public.gmane.org
Tue May 24 00:57:27 UTC 2005


  ----- Original Message ----- 
  From: "Kevin C. Krinke" <kckrinke-eqjHHVKjh9GttCpgsWEBFlaTQe2KTcn/@public.gmane.org>
  To: "tlug" <tlug-lxSQFCZeNF4 at public.gmane.org>
  Sent: Monday, May 23, 2005 5:35 PM
  Subject: Re: [TLUG]: Perl Syntax


  > 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?
  >
  The problem is interesting, because it touches on a number of concepts 
that really requires a lot of supplemental readings.
  Thanks for your help, Kevin.
  John


--------------------------------------------------------------------------------



--
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