Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

RE: Setting up signal handlers for an object with access to $self

by chromatic (Archbishop)
on Apr 19, 2000 at 23:02 UTC ( [id://8066]=note: print w/replies, xml ) Need Help??


in reply to Setting up signal handlers for an object with access to $self

Why not just make a reference to a subroutine? Here's my take on it:
#!/usr/bin/perl -w use strict; sub do_something { print "This is what I do.\n"; exit; } $SIG{INT} = \&do_something; while (1) {}
That's one less layer of indirection and conceptually clearer to me, at least. TIMTOWTDI!

Replies are listed 'Best First'.
RE: RE: Setting up signal handlers for an object with access to $self
by ZZamboni (Curate) on Apr 19, 2000 at 23:03 UTC
    The point is to give the signal handler access to an object. If you simply point the signal handler to a subroutine, you do not have a way of accessing $self, unless it is stored in a class variable. By defining the signal handler with a closure, you can call the signal handler as if it were a method instead of a regular subroutine, therefore giving it access to $self (and the ability to access its methods and data).
      Hey, you're right! Very nice. (The word closure makes it obvious now.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://8066]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found