in reply to Re: Array Processing
in thread Array Processing
This won't work if the array contains anything that is false in boolean context, like 0, '', or undef. You really need to explicitly check the array's length somehow.while (my $a = shift @a) {
If you're really intent on squeezing the assignment into the while loop, try:
This works because when evaluated in scalar context, the list assignment ( (list) = something ) returns the number of items in the right-hand side list. This little obscurity of syntax is probably one of the toughest to come to grips with, but it can be quite elegant at times.while ( (my $a, @a) = @a ) {
In this case, I wouldn't actually use it since it reassigns most of @a to itself every time and is very inefficient in that respect.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Array Processing
by japhy (Canon) on Oct 08, 2005 at 15:36 UTC | |
by liverpole (Monsignor) on Oct 08, 2005 at 16:37 UTC | |
by blokhead (Monsignor) on Oct 08, 2005 at 18:37 UTC | |
by liverpole (Monsignor) on Oct 08, 2005 at 20:10 UTC | |
by BUU (Prior) on Oct 08, 2005 at 20:09 UTC | |
by japhy (Canon) on Oct 09, 2005 at 19:37 UTC | |
by Aristotle (Chancellor) on Oct 09, 2005 at 19:52 UTC |