M
Matthew Horsfall
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 <>
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 <>