in reply to Signal handlers and scoped variables, or Nested subs?

I want the handler to use some variables from outside the handler.

Sounds like you want a closure

sub outer { my $var; local $SIG{INT} = sub { ... ...[ Read from and/or write to $var ]... ... }; ... }

Unrelated notes:

Replies are listed 'Best First'.
Re^2: Signal handlers and scoped variables, or Nested subs?
by kwaping (Priest) on May 12, 2006 at 22:38 UTC
    Thank you for both of your replies.

    The usage of srand was an artifact from before I put the code into sub outer. Thank you for reminding me to remove it!

    I am putting the use statement inside the sub because I want to eventually make the sub into an object method. I don't want to require the main program to know that it should use IO::Socket if it wants to use this method. When I move the sub into the package file, I will remove the use statement from the sub itself and put it into the package file.

    ---
    It's all fine and dandy until someone has to look at the code.