Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Hello all, is there some way for code within a signal handler to affect the greater program? I found Setting up signal handlers for an object with access to $self, which has allowed me access to my data within the signal handler, but neither changes to the object nor the %ENVironment seem to persist. I suspect it's not possible, but am wondering if there's something I am overlooking.

For those curious, the goal is to install a handler that will handle broken pipes elegantly and fail over to a fallback. $SIG{PIPE} = 'IGNORE' is insufficient, and wrapping the calls that work with the pipe in eval{} fails the elegance test… Cheers!

UPDATE: In the end it turned out to be possible to get information out of the signal handler, but block eval was still required. However I hit upon a relatively elegant means of using it: Rather than wrapping multiple statements within eval. I decided to put everything in an eval block, and use it as a replacement for do in my control structure e.g;

eval{ ... } while ($condition);

In Bob We Trust, All Others Bring Data.

In reply to Spooky actions from a signal handler possible? by belg4mit

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.