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:
Your usage of srand makes things less random. Remove it.
Replace
$SIG{...} = ...;
with
local $SIG{...} = ...;
to limit the scope where your handler takes effect.
Why is use IO::Socket; inside the sub? That's confusing!
|
|---|
| 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 |