in reply to Different result for 'foreach' vs 'while shift' arrayref
With this one:
while (my $result = shift(@$rowcache) )
If @$rowcache contains a false value (e.g. undef, or the empty string, or the number 0), then when that value is reached, the condition will become false, so the while loop will exit.
If you really want to use while, then you could do:
while (my ($result) = @$rowcache ? shift(@$rowcache) : ())
Or, if you know that @$rowcache consists of only defined values (no undefs, but perhaps some empty strings and zeros), you could do:
while ( defined(my $result = shift @$rowcache) )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Different result for 'foreach' vs 'while shift' arrayref
by Your Mother (Archbishop) on Apr 18, 2014 at 23:57 UTC | |
by tobyink (Canon) on Apr 19, 2014 at 09:29 UTC |