Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Abusing Map

by AnomalousMonk (Chancellor)
on May 16, 2018 at 20:41 UTC ( #1214690=note: print w/replies, xml ) Need Help??


in reply to Abusing Map

WRT this recent discussion thread: Forget map, if you want to take it up just that extra quantum energy level that allows you to achieve truly epic abuse, use grep:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @ra = (1, 2, 3, 4); ;; my @rb; grep $rb[ $_-1 ] = $ra[ $_-1 ] + $ra[ $_ ], 1 .. $#ra; dd \@rb; " [3, 5, 7]

Update: Also works with
    grep $rb[ $_ ] = $ra[ $_ ] + $ra[ $_+1 ], 0 .. $#ra-1;
with one fewer arithmetic operation per iteration!


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-11-13 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (149 votes). Check out past polls.

    Notices?