http://qs321.pair.com?node_id=1214704


in reply to Abusing Map

I'm surprised nobody mentioned reduce yet.

Have a look a List::Util and/or List::MoreUtils

update

Sorry reduce is wrong (it returns a scalar) but close ...

update

we had similar discussions before, but I was only able to find "reduce like iterators" yet

Too tired to look further.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Abusing Map
by BrowserUk (Pope) on May 17, 2018 at 03:45 UTC
    I'm surprised nobody mentioned reduce yet.

    Because that doesn't work to produce the results the op wants.

    So mentioning it would be silly.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
Re^2: Abusing Map
by ikegami (Pope) on May 18, 2018 at 08:07 UTC
    use List::MoreUtils qw( zip6 ); my @b = map { $_->[0] - $_->[1] } zip6 @{[ @a[0..$#a-1] ]}, @{[ @a[1..$#a] ]};

    :)

Re^2: Abusing Map
by Anonymous Monk on May 17, 2018 at 14:36 UTC