in reply to $SIG{ALRM} with a class method
You can call a class method like a function in a manner very similar to what you have with this:
$SIG{ALRM} = \&Classname::method; # update: no parens, force of habit. + Thanks bbfu.
However, the class name will not be prepended to the argument stack, which class methods very often expect will be the case. So as others have suggested, the approach you probably want is to use an anonymous sub:
$SIG{ALRM} = sub { Classname->method() };
Now you can use variables in the new handler, like in the first note in this thread, just so long as they are in visible scope of the handler. So, a global var, or a lexical in the enclosing scope will be accessible.
|
|---|