in reply to Reference to non-existing function without warning or error

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)

Replies are listed 'Best First'.
Re^2: Reference to non-existing function without warning or error
by Anonymous Monk on Aug 03, 2007 at 20:04 UTC
    The warning was 'Name "main::noSuchFunction" used only once: possible typo', because I used that name only once (typically for a typo). It was not a warning about referencing an undefined function.