in reply to shift in list context buggy?
The problem here is that you are trying to use the return value of shift to determine if the array is empty. And since you appear to want undef to be "a legal value", there is no value that shift could return to indicate that the array is now empty.
The problem is avoided - or rather you avoid creating a problem -- by making the loop condition test the actual condition -- whether the array is empty -- and not conflating it with an operation that is unrelated to that condition:
while( @array ) { my $x = shift @array; # use $x. }
This isn't a "Perl design decision" to be regretted; it's a programmer error to be avoided.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: shift in list context buggy?
by LanX (Saint) on Nov 09, 2013 at 16:56 UTC | |
by BrowserUk (Patriarch) on Nov 09, 2013 at 23:24 UTC |