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;
In reply to Re: Abusing Map (Corrected second code block)
by BrowserUk
in thread Abusing Map
by writch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |