Nothing prevents you from taking the reference of a scalar, array, hash, glob, function or whatever that hasn't been declared.

use strict 'vars'; will prevent you from mentiong variables that haven't been declared, but it will neither prevent you from mentioning a sub that hasn't been declared, nor prevent you from making a reference to something that doesn't exist.

I don't see any reason to allow making a reference to a function that don't exist. It could simply be a case that noone thought to make special. Or maybe they didn't see the need to make it special since Perl usually catches the problem when the code attempts to execute the referenced non-existing function. If that's the case, one could argue the bug is in die.

Using 'noSuchFunction' instead of \&noSuchFunction did not help (and is not recommended in perlvar.pod), only *noSuchFunction generated a warning.

Odd. I would expect it to give no warning. In fact, I can't replicate your result. I can't get *noSuchFunction to give a warning.

use strict; use warnings; $_ = \&noSuchFunction; print("$_\n"); $_ = *noSuchFunction; print("$_\n"); $_ = *noSuchFunction{CODE}; print("$_\n"); $_ = \*noSuchFunction; print("$_\n");

outputs

CODE(0x225e58) *main::noSuchFunction CODE(0x225e58) GLOB(0x226b9c)

In reply to Re: Reference to non-existing function without warning or error by ikegami
in thread Reference to non-existing function without warning or error by Anonymous Monk

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.