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!
In reply to Re: Signal handlers and scoped variables, or Nested subs?
by ikegami
in thread Signal handlers and scoped variables, or Nested subs?
by kwaping
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |