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

Re: Variable Scope in a Signal Handler?

by Fastolfe (Vicar)
on Nov 01, 2001 at 22:02 UTC ( [id://122615]=note: print w/replies, xml ) Need Help??


in reply to Variable Scope in a Signal Handler?

Yes, if you use a global variable or if your signal handler is a closure with a lexical in the scope you're after. Try this simple test and see if it prints out what you expect:
{ my $var = 1; $SIG{HUP} = sub { print "HUP; \$var=$var\n"; $var++; }; } print "in main program, \$var=$var\n"; kill('HUP', $$); print "in main program, \$var=$var\n"; kill('HUP', $$); print "in main program, \$var=$var\n";
Then try moving $var into the main program and declare it with 'use vars'.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-10-12 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.