Re: catch_int\catch_hup subroutine

From: Brian McCauley (nobull_at_mail.com)
Date: 02/25/05


Date: Fri, 25 Feb 2005 18:37:01 +0000


DJ wrote:
>
> $SIG{HUP} = \&catch_hup;
> $SIG{INT} = \&catch_int;
>
> This is all defined in the same script file. I would like to move the
> subroutine definitions to a Perl module so that I can reuse these
> definitions in different Perl scripts. So when I add the two
> subroutines (catch_hup and catch_int) into my Module.pm file, I would
> like to call them as follows:
>
> $SIG{INT} = Module->catch_hup;
> $SIG{HUP} = Module->catch_int;

No, do the same thing you did in the first case:

  $SIG{INT} = \&Module::catch_hup;
  $SIG{HUP} = \&Module::catch_int;

Or, of couse, you could have Module export them (using Exporter).

> Is that even possible with Perl? The code that works was inherited and
> I have a basic understanding of how it works. Currently I have other
> subroutines defined in my Perl module that work fine. However, I'm
> sure with signals, it doesn't work the same.

No there is no difference, if you had said...

  $SIG{HUP} = catch_hup;
  $SIG{INT} = catch_int;

...it would not have worked either.