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?


In reply to Where does the spurious error message come from? by kikuchiyo

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.