Leocharre, you're right on in being cautious of the truth of the loop condition. Which is necessary due to the lack of while(<>)-style magic in a mere while($_=shift){}.
Consider how the usual looping variants work or mostly fail, or just ask Perl with a simple, cute and short one-liner:
perl -e 'use Data::Dumper; @a=(1,0,undef,2); print Dumper(@a); print " +1=$_=\n" foreach (@a); @ARGV=@a; print "2=$_=\n" while($_=shift @a); +@a=@ARGV; print "3=$_=\n" while($_=shift @a,defined $_); @a=@ARGV; pr +int "4=$_=\n" while($_=shift);'
PS: ad local: local($_) helps to not hurt the caller (but isn't e.g. necessary in a foreach(@a) scope), while my($_) (since 5.10) helps the current scope to not be hurt by called routines (and signal handlers, etc).
\Peter, who is wondering whether the line-eater did like the taste of his attempted .sigIn reply to Re: using shift and $_ in loop
by jakobi
in thread using shift and $_ in loop
by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |