in reply to Paranormal leakage of previous value from conditionally set lexical variable

perlsyn:

NOTE: The behaviour of a my, state, or our modified with a statement modifier conditional or loop construct (for example, my $x if ...) is undefined. The value of the my variable may be undef, any previously assigned value, or possibly anything else. Don't rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons.
$ perl -Mdiagnostics -wMstrict -le '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. ...

Replies are listed 'Best First'.
Re^2: Paranormal leakage of previous value from conditionally set lexical variable
by Anonymous Monk on Mar 09, 2016 at 19:53 UTC

    (OP here)

    Thanks, so at least it is known and documented.

    I don't like the fact that as opposed to your code, I don't get any warning, the code just silently fails, and that this behavior is in Perl since at least 5.8, and according to the diagnostic message it is a known bug that they meant to fix but didn't.

      This won't help in your case, but fwiw, Perl::Critic catches this.