in reply to performing a function on corresonding array elements
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @set = ( { 'id' => '1462', 'items' => [ '9.9', '10.1', '10.3', '10.5', '10.8', '10.94' ], }, { 'id' => '1463', 'items' => [ '3.1', '4.3', '4.5', '4.6', '4.7', '4.8' ], } ); my @totals; for my $href ( @set ) { $totals[ $_ ] += $href->{items}[ $_ ] for 0 .. $#{ $href->{items} +}; } print Dumper \@totals; __END__ C:\test>540833 $VAR1 = [ '13', '14.4', '14.8', '15.1', '15.5', '15.74' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: performing a function on corresonding array elements
by codeacrobat (Chaplain) on Apr 03, 2006 at 06:23 UTC | |
by BrowserUk (Patriarch) on Apr 03, 2006 at 12:39 UTC | |
|
Re^2: performing a function on corresonding array elements
by vindaloo (Acolyte) on Apr 03, 2006 at 02:29 UTC |