From: Matthew Horsfall on
It seems that while() loops don't localize $_ in certain situations,
whereas for loops do.

The following works fine:

$ echo Test | perl -e 'for (qw(Word)) { for (<STDIN>) { print "$_";
exit;} }'
Test

Whereas the following crashes:

$ echo Test | perl -e 'for (qw(Word)) { while (<STDIN>) { print "$_";
exit;} }'
Modification of a read-only value attempted at -e line 1.

Is this expected behavior?

I will note this only seems to happen when modifying $_ using <>
From: Matthew Horsfall on
On Jul 14, 9:42 am, Willem <wil...(a)turtle.stack.nl> wrote:
> Matthew Horsfall wrote:
> ) Is this expected behavior?
>
> Yes.  for() aliases whereas while() assigns.
>

That clarifies things greatly. Thank you.