kikuchiyo has asked for the wisdom of the Perl Monks concerning the following question:
I've come across a strange case while refactoring some code at $work. This is a minimal example:
#!/usr/bin/perl use strict; use warnings; use List::Util qw/any/; sub foo { ###my $undeclared_variable = "Printing inside foo()\n"; print $undeclared_variable; } sub bar { my $params = {something => 'whatever'}; if (any { $params->{something} eq $_ } qw(some options or whatever +)) { print "Printing inside bar()\n"; } } foo(); bar();
This program is of course broken, $undeclared_variable is, true to its name, undeclared. However, when ran with perl 5.36.1, I get the following error messages:
Global symbol "$undeclared_variable" requires explicit package name (d +id you forget to declare "my $undeclared_variable"?) at perl_bad_erro +r_msg.pl line 9. Type of arg 1 to List::Util::any must be block or sub {} (not referenc +e constructor) at perl_bad_error_msg.pl line 14, near "qw(some option +s or whatever)) " Execution of perl_bad_error_msg.pl aborted due to compilation errors.
The first error message is valid, the second, however, is not. That line is fine, and indeed if you uncomment the variable declaration in foo(), the program runs without errors or warnings.
So where does the spurious error message come from? Does the presence of the first error push the interpreter in a state where the magic brace-guessing heuristics is broken?
|
---|