Once more, a great answer has bit the dust in testing. I wanted to give jacques a different answer than I did to Using STDERR and timestamps to write to a log file, namely,

local *CORE::GLOBAL::die = sub (@) { die scalar(localtime()), ' ', @_; };
but die keeps on dieing the same old way.
$ perl -e'local *CORE::GLOBAL::die = sub (@) {CORE::die(scalar(localti +me()), " ", @_);}; die "Foo!"' Foo! at -e line 1. $

Apparently, die is not overridable. It has a prototype,

$ perl -e'print prototype "CORE::die"' @$
and it doesn't appear on diotalevi's toke.c list in Re: !Overriding Builtin print. Now how do we know which builtins are overridable? Is die somehow special-cased to not be overridden, as glob and readline are to permit it?

Overriding builtins is indeed a tricky business.

Added: Thanks, tye++ and leriksen++. You showed me something I didn't really understand before. It looks like builtins are outside both lexical and dynamic scope, being resolved sometime while compiling. Localizing them has no effect, and the last-compiled override is the one which counts. It's still a little freaky:

BEGIN { *CORE::GLOBAL::warn = sub (@) { CORE::warn(scalar(localtime), " ", @_); }; warn "Foo!"; } BEGIN { *CORE::GLOBAL::warn = sub (@) { CORE::warn( @_); }; } warn "Bar!"' __END__ Foo! at -e line 1. Bar! at -e line 1.
It looks like BEGIN blocks are all compiled to a single parse tree before they run, but that's only guessing.

After Compline,
Zaxo


In reply to Yet Another Override Oddity by Zaxo

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.