in reply to I can't see why this shorthand doesn't behave like the verbose form

How does it not work? Are you sure you want to declare the variable inside the eval rather than declaring it outside and then merely set it inside?

Also, what makes you think that eval is shorter or simpler than the first code snippet? You're free to use the A?B:C in the first snippet too.

  • Comment on Re: I can't see why this shorthand doesn't behave like the verbose form
  • Download Code

Replies are listed 'Best First'.
Re^2: I can't see why this shorthand doesn't behave like the verbose form
by isync (Hermit) on Mar 25, 2012 at 11:44 UTC
    O'Reilly's Advanced Perl Programming sais that eval'ed code is executed in the environment of the surrounding code, just as if the eval wasn't there - so declaring it inside or outside of the eval block is irrelevant
    Anyway, the eval just added noise to the core of my post, that's why I removed it from the follow up example.

      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.
        Out of my scope ;)
        I thought, in eval's case the { } were just nice decoration...