First time trying to work with signals in Perl.
Reviewing example I try it, but not able to get it work for 'exit'.
I hope, I am correct, assuming, that the ending any code by

exit $return_code;

the $SIG{EXIT} should be de-referenced and processed?!
So, I have such code, that, I assume, should, but does not process signal handling:

#!/bin/perl sub trp_h{ print "\nIn 'trp_h()'. ". "\nReceived parameters \@_: ".(join ", ",@_). "\n\$! as a number: ".($!+0).", as a string: ".(" ".$!). "\n now 'sleep 5' before return."; sleep 5; } $SIG{EXIT}='trp_h'; print "\nSet handler: $SIG{EXIT}\n"; exit(5); print "after first exit"; $SIG{EXIT}=\&trp_h; print "\nSet handler to code: $SIG{EXIT}\n"; exit(3); print "after second exit\n"; print "Restoring to default\n"; $SIG{EXIT}='DEFAULT'; exit(2); exit 1;

Please, help me understand what is wrong, or,
if I mistaken on assumption that the 'exit()' is processed by the $SIG{EXIT},
how it could be handled to process activity, such as in UNIX 'trap "..." EXIT' command?

Thanks!


In reply to trap signal 'exit': why I am not able to have it work?? by alex5161

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.