in reply to Fold a list using map splices
Iterating your splicing map over the same array its block modifies as a side effect is a really dirty approach though; no wonder you have to test $_ to guard against its failures. The right way to do this is in two steps:
or maybe the straightforwardmy @spliced; push @spliced, [ splice @_, 0, $num_elements ] while @_; my @result = map func1($_), @spliced;
It's awkward in Perl 5, that's true. Perl 6 is going to do away with this limitation of the list iteration functions and operators.my @result; push @result, func1([ splice @_, 0, $num_elements ]) while @_;
Makeshifts last the longest.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Fold a list using map splices
by hiseldl (Priest) on Feb 20, 2003 at 15:25 UTC | |
by Aristotle (Chancellor) on Feb 20, 2003 at 17:54 UTC | |
by hiseldl (Priest) on Feb 20, 2003 at 21:28 UTC |
In Section
Cool Uses for Perl