Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: trap signal 'exit': why I am not able to have it work??

by afoken (Chancellor)
on Oct 31, 2017 at 12:50 UTC ( [id://1202421]=note: print w/replies, xml ) Need Help??


in reply to Re: trap signal 'exit': why I am not able to have it work??
in thread trap signal 'exit': why I am not able to have it work??

you can't switch "exit" handlers midstream, and you can't unregister END{} blocks,

But you can enable or disable code in the END blocks by using flag variables:

>cat demo.pl #!/usr/bin/perl use v5.12; use warnings; our $endFlag; END { if ($endFlag) { say "End flag is set, have to so some cleanup"; say "Wash, rinse, repeat" for 1..5; } else { say "Nothing to do"; } } $endFlag = $ARGV[0]; say "How will this end?"; >perl demo.pl 0 How will this end? Nothing to do >perl demo.pl 1 How will this end? End flag is set, have to so some cleanup Wash, rinse, repeat Wash, rinse, repeat Wash, rinse, repeat Wash, rinse, repeat Wash, rinse, repeat >

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-16 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found