in reply to Re: Unshift and push inside of map operation.
in thread Unshift and push inside of map operation.
while (my $item = shift @toprocess)
will fail if one of the items evaluates to false. You want to check "if an item has been returned", not "if an item has been returned and its true". Fix:
while (my ($item) = shift @toprocess)
A list assignment in scalar context returns the number of items being assigned.
Update: Oops, I'm used to dealing with iterators that return () when out of data. As per tye's reply, my fix makes things worse. The following allows false values without introducing an infinite loop:
while (@toprocess) { my $item = shift @toprocess;
Due to the extra complexity, it might make more sense to the simpler original if it's safe.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unshift and push inside of map operation. (test)
by tye (Sage) on Sep 23, 2008 at 05:08 UTC | |
by JadeNB (Chaplain) on Sep 23, 2008 at 18:17 UTC |