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