in reply to Assigning from post fix if exists breaks local scoping?

G'day Nath,

Welcome to the monastery.

Perhaps have a chat with Robert who asked the same thing 27 minutes before you.

Curiously, he also managed to boil it down to exactly the same code as you did.

See "postfix syntax enlightenment".

-- Ken

  • Comment on Re: Assigning from post fix if exists breaks local scoping?

Replies are listed 'Best First'.
Re^2: Assigning from post fix if exists breaks local scoping?
by swinging_simian (Initiate) on Mar 28, 2014 at 19:04 UTC
    Hmm,
    It seems like my code 'leaked' out of the office. Although the solution still does not address why the scoping is broken. Time for a little light reading methinks.

    Thanks for the redirect.

    Nath

      This issue was also recently raised on P2P/RT, here. Also:

      $ perl -wMdiagnostics -e 'my $x if 0' Deprecated use of my() in false conditional at -e line 1 (#1) (D deprecated) You used a declaration similar to my $x if 0. There has been a long-standing bug in Perl that causes a lexical variable not to be cleared at scope exit when its declaration includes a false conditional. Some people have exploited this bug to achieve a kind of static variable. Since we intend to fix this bug, we don't want people relying on this behavior. You can achieve a similar static effect by declaring the variable in a separate block outside the function, eg sub f { my $x if 0; return $x++ } becomes { my $x; sub f { return $x++ } } Beginning with perl 5.9.4, you can also use state variables to have lexicals that are initialized only once (see feature): sub f { state $x; return $x++ }