How do you reproduce "Can't use an undefined value as a symbol reference " in Perl?
Can't use an undefined value as a symbol referenc开发者_开发百科e
Anyone knows how to reproduce it?
print $bar 1;
emits the error. you can see a nice explanation of what it means on this perlmonks thread
as explained by splain
:
Can't use an undefined value as a symbol reference (#1)
(F) A value used as either a hard reference or a symbolic reference must
be a defined value. This helps to delurk some insidious errors.
Here's the simplest form:
say *{my $a}{SCALAR}; # OR say ${ *{my $a} };
perl -we '$x = shift; *$x = sub {42}; print $x->()'
This code prints 42 if called with ANY argument (incl. ''
), but gives the needed warning w/o args.
精彩评论