when running code like this:
use strict;
print Dumper "something";
nothing is printed out and no error occurs during compile and runtime. Why does this happen? Why doesn't strict
prevent this code from running? Why is there no error at runtime, even though Dumper is unknown?
I know it produces a warning when those are explicitly enabled, but I'm interested why is this code considered "correct" in any way.
If you had begun with the standard boilerplate, then you would know:
The answer is that your program is syntactically but not semantically correct. You are printing
"something"
to the unopenedDumper
filehandle-object, becauseDumper
is in the dative slot for theprint
method call. That makesDumper
print
’s invocant. But you never opened a handle by that name, so you are printing to an uninitialized filehandle.Use my boilerplate. PLEASE!
One of the valid syntaxes for
print
isIn your program Perl is treating
Dumper
as a filehandle glob.Running this code with warnings enabled will tell you:
print() on unopened filehandle Dumper at ...