Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Abusing Map

by AnomalousMonk (Archbishop)
on May 16, 2018 at 20:41 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found