1. Introspection

  2. Does Perl provide any way to programmatically list the "names" of all the Perl built-in functions? By "name" I mean the string, e.g. "y", that when appended to the string "CORE::" can be given to CORE::prototype as its argument to obtain the prototype of the corresponding Perl built-in.

  3. Overriding built-ins

  4. Some Perl built-ins are overridable, others aren't. What is the best way to find out which are the ones that cannot be overridden?

    For all non-overridable built-ins CORE::foo, the expression CORE::prototype('CORE::foo') returns undef, but the converse is not true. For example, CORE::prototype('CORE::system') returns undef, but CORE::system is overridable, as shown by the following snippet:

    use strict; use warnings; use subs 'system'; sub system { warn "this is not the real system\n" } warn "about to test system\n"; system 'date'; warn "done testing system\n"; __END__ about to test system this is not the real system done testing system
    For other built-ins with a CORE::prototype return value of undef, however, the above trick won't work. Either the overriding function will be silently ignored (as happens if one tries to override CORE::print), or Perl will react more spectacularly, such as seg-faulting if one tries to override CORE::require.

    So, is there a way to determine which built-ins are overridable, other than trial and error?

(Both questions prompted only by curiosity.)

the lowliest monk


In reply to 2 Qs: introspection & overriding built-ins by tlm

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.