in reply to Re^3: Array Processing
in thread Array Processing
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 =
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Array Processing
by blokhead (Monsignor) on Oct 08, 2005 at 18:37 UTC | |
by liverpole (Monsignor) on Oct 08, 2005 at 20:10 UTC | |
|
Re^5: Array Processing
by BUU (Prior) on Oct 08, 2005 at 20:09 UTC | |
|
Re^5: Array Processing
by japhy (Canon) on Oct 09, 2005 at 19:37 UTC | |
|
Re^5: Array Processing
by Aristotle (Chancellor) on Oct 09, 2005 at 19:52 UTC |