you do something like:while ($line = <$fh>) { # ... }
But then, when I looked more carefully at the idiom you suggested, there's a subtle bug in: while ( (my $a, @a) = @a ) {". I realized it doesn't, in fact, reasign most of @a to iteslf every time, because you're declaring my @a (along with my $a), so it's a different @a that you're doing the assignment to! Also, when you run it, you get an infinite loop:while (defined($line = <$fh>)) { # ... }
And japhy, you've got an interesting idiom too, but it also doesn't do quite what you want, because the ",1" makes the expression eternally true, so you also get an infinite loop even after @a is exhausted. So for now, I'll stick with the "while (defined($a = shift @a))" syntax.my @a = qw( 1 2 3 4 5 ); while (my ($a, @a) = shift @a) { printf "Next value = $a\n"; printf "Size of \@a = %d\n", 0 + @a; } # When run ... infinite loop! # (Note that "Size of @a" shows the temporary @a, not the original) Next value = 1 Size of @a = 0 Next value = 2 Size of @a = 0 Next value = 3 Size of @a = 0 Next value = 4 Size of @a = 0 Next value = 5 Size of @a = 0 Next value = Size of @a = 0 Next value = Size of @a = 0 Next value =
In reply to Re^4: Array Processing
by liverpole
in thread Array Processing
by Rajeshk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |