As already mentioned, see also Is $^M a leftover April Fool? for lots of related discussion.

In short, the idea seems to be that when Perl runs into an "out of memory" situation, it goes on to die (which can be trapped).  Immediately before that it frees the previously allocated emergency buffer (the PV behind $^M), so any exception handler would have some memory resources to do its job of cleaning up/freeing more memory.  For this kind of out-of-memory handling to be active, Perl has to be built with -DPERL_EMERGENCY_SBRK (AFAICT).

Although investigation of the sources (in particular malloc.c) confirms this theory, no one seems to have been able to come up with a short snippet demonstrating the behavior...  at least not with any recent version of Perl.  (I haven't tried it myself so far, but out of mere curiosity I might give it a go later, if time permits.)


In reply to Re: die rather than exit on out-of-memory failure? by Anonyrnous Monk
in thread die rather than exit on out-of-memory failure? by chm

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.