[SP-pm] Soma de duas listas

Thiago Glauco Sanchez thiagoglauco at ticursos.net
Thu Jul 22 08:27:46 PDT 2010


Em 22/07/2010 12:08, Pinguim Azul escreveu:
> Hi,
>
> Qual o menor jeito de somar duas listas, elemento a elemento? O melhor
> que eu achei foi pelos indices, mas imagino que tem coisa melhor:
>
> @a=(1,2,3); @b=(4,5,6);
> @c=map{$a[$_]+$b[$_]}(0..($x=@a)-1);
>    
cara, para saber o último índice de um array use $#a em vez de ($x=@a)-1
> print "@c"
>
>    


-- 
What is the sound of Perl? Is it not the sound of a wall that people have
stopped banging their heads against?
—Larry Wall

Thiago Glauco Sanchez
Intrutor Perl e Redes
www.ticursos.net



More information about the SaoPaulo-pm mailing list