in reply to Re: Variable being clobbered by a seemingly unrelated while loop
in thread Variable being clobbered by a seemingly unrelated while loop

$_ is localized in for loops, but not while loops. (Indeedy any variable is localized in a for loop. Even lexical variables.)

Replies are listed 'Best First'.
Re^3: Variable being clobbered by a seemingly unrelated while loop
by choroba (Cardinal) on Oct 08, 2014 at 11:47 UTC
    Even lexical variables.
    But,
    my $x = 3; local $x'
    leads to
    Can't localize lexical variable $x at 1.pl line 2.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      I guess tobyink means:

      my $x='foo'; for $x ('bar') { print "$x\n"; } print "$x\n"; __END__ bar foo
Re^3: Variable being clobbered by a seemingly unrelated while loop
by wrog (Friar) on Oct 10, 2014 at 18:29 UTC
    Right. No I was thinking $_ was implicitly localized in subs, but now I see perlsub explicitly warns against expecting this.