in reply to Re^2: I can't see why this shorthand doesn't behave like the verbose form
in thread I can't see why this shorthand doesn't behave like the verbose form

That does not change the scoping rules , {   } introduces a new scope

$ perl -le " eval { my $foo = 1; } ; print $foo; " $ perl -le " use strict; eval { my $foo = 1; } ; print $foo; " Global symbol "$foo" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
  • Comment on Re^3: I can't see why this shorthand doesn't behave like the verbose form
  • Download Code

Replies are listed 'Best First'.
Re^4: I can't see why this shorthand doesn't behave like the verbose form
by isync (Hermit) on Mar 25, 2012 at 17:02 UTC
    Out of my scope ;)
    I thought, in eval's case the { } were just nice decoration...

      :) I wonder what happens when you get rid of them

      $ perl -le " eval my $foo = 1; " Can't modify eval "string" in scalar assignment at -e line 1, near "1; +" Execution of -e aborted due to compilation errors. $ perl -MO=Deparse,-p -le " eval my $foo = 1; " Can't modify eval "string" in scalar assignment at -e line 1, near "1; +" -e had compilation errors. BEGIN { $/ = "\n"; $\ = "\n"; } (eval(my $foo) = 1); $ perl -le " eval( my $foo = 1;) " syntax error at -e line 1, near "1;" Execution of -e aborted due to compilation errors. $ perl -le " eval( my $foo = 1) " $ perl -le " eval( my $foo = q/print 666/ ) " 666

      Uh oh :)