As mentioned by others, that will fail if the array may contain false or undefined values. You can do something similar by keeping the entire assignment in list context and making sure to assign a list:
while( my ( $a ) = @a ? shift @a : () ) { # ... }
Note the parens around $a: they make all the difference. They put the my (and thus the entire expression) in list context, and so the boolean value depends on the number of elements assigned. The ternary operator contortion on the right side ensures that when @a is empty, an empty list is assigned, so the loop aborts correctly.
Try putting empty strings, zeros or undefs in the array: you’ll find it will always do exactly what it’s supposed to.
However, elegant is not what it is. I’d much rather use while( @a ) and do a separate shift – far fewer subtleties to contend with.
Makeshifts last the longest.
In reply to Re^2: Array Processing
by Aristotle
in thread Array Processing
by Rajeshk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |