But it's a horrible way to get the answer. It requires an extra trapped exception, and parsing a text error message. The former is expensive, and the latter is not generally considered good practice for any number of reasons.
It's expensive? Really? Considering the program is terminating (due to the die), which requires full garbage collection, calling DESTROY, etc, does one really care about an addition trapped exception? I presume you aren't going to die inside a tight loop.

As the not considering good practice, is that really an issue? "Good practice" is subjective, and IMO, it isn't "good practice" to take "good practices" as dogma. It often doesn't hurt to be pragmatic.

Clearly, die figures it out - so it's available somewhere.
Yes. I advice you to study the util.c file that comes with the perl distribution. It may unlock die's secrets.

In reply to Re^5: How do I replicate die's magic with $. ? by JavaFan
in thread How do I replicate die's magic with $. ? by tlhackque

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.