in reply to lexical weirdness(?)

It looks like the my does not reset the variable value to undef if it is initialized through a test.

Those 2 snippets are not equivalent either:

foreach (1..2) { my $i; print "$i\n"; $i++; }
 foreach (1..2) { my $i=0 if( 0); print "$i\n"; $i++; }

Now is this a bug or a feature?

Replies are listed 'Best First'.
RE: Re: lexical weirdness(?)
by Anonymous Monk on Oct 25, 2000 at 19:48 UTC
    my $foo if 0;
    

    This is a "feature" that has been covered on p5p... when the "if" fails, the lexical variable is not re-allocated and so stays whatever it was. I believe the consensus was not to expect this feature to stick around.

      Well, it was an accident that some decided was a feature causing "the rest of us" to put them straight that this "feature" isn't something they should expect to never be "fixed". (:

              - tye (but my friends call me "Tye")