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


in reply to Abusing Map

You could do:

@b = map{ $a[ $_-1 ] + $a[ $_ ] } 1 .. $#a;

For small arrays, it doesn't cost too much.

Update: corrected bounds as pointed out by AnomalousMonk

But post-fix for is probably better:

$b[ $_-1 ] = $a[ $_-1 ] + $a[ $_ ] for 1 .. $#a;

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