in reply to Scalar assignment with loop iterator considered bad?

It's interesting that they didn't say in what way it was less desirable. It made me wonder whether they weren't thinking of the trouble caused by declaring a my variable in a modified statement:
my $foo .= ",$_" for qw(1 2 3); print "$foo\n";
Because there is no block, $foo is in scope for the print. But for reasons I can't really explain, it's not handled as you might expect, and $foo is undefined in the print. If you declare $foo separately prior to the for, then it works as expected.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Scalar assignment with loop iterator considered bad?
by wazoox (Prior) on Jul 23, 2005 at 14:16 UTC
    I suppose this construct does indeed create a block, even if there isn't any curly bracket. That a very good reason to prefer the "map" or the "join" versions: no hidden scope problem.
      The best explanation I can find is here.

      Caution: Contents may have been coded under pressure.