It's because in the second instance you're looping over a constant value in the
for and the trying to assign that in
my_method e.g
sub readstuff { return while <> }
print readstuff for 'a constant value';
__output__
Modification of a read-only value attempted at - line 1.
Where the
while really compiles as
return while defined($_ = <>). As has been mentioned before in
IlyaM's
while(<>) { ... } considered harmful, be careful when implicitly using
$_ in subroutines and methods.
HTH
_________
broquaint