in reply to Frustrating Error: "Global symbol requires explicit package name" - Can't see why?

And, once you know it, it's easy to duplicate the error:

c:\@Work\Perl\monks>perl -wMstrict -le "sub foo (&@) { return 42; } ;; my $x = foo { } print $x; " Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.


Give a man a fish:  <%-{-{-{-<

  • Comment on Re: Frustrating Error: "Global symbol requires explicit package name" - Can't see why?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Frustrating Error: "Global symbol requires explicit package name" - Can't see why?
by LanX (Saint) on Aug 25, 2015 at 01:49 UTC
    Yeah nothing specific about threads, just the fact that my declarations only start being effective after the next semicolon.

    This was done to allow constructs like

    my $x = $x++;

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      When I first read LanX's reply, I was confused because the statement all on its own is an error. But LanX /msg-ed me that the rule allows access to same-named lexicals in surrounding scopes:

      c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 42; if ($x) { my $x = $x++; print $x; } print $x; " 42 43
      Now I understand.


      Give a man a fish:  <%-{-{-{-<