Prev: FAQ 6.1 How can I hope to use regular expressions without creating illegible and unmaintainable code?
Next: while() doesn't localize $_ but for() does in some situations.Is this expected?
From: Matthew Horsfall on 14 Jul 2010 09:23 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 14 Jul 2010 10:06
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. |