in reply to Adding two lists together

Mark,

For the 2 lists try this to always get every item. This assumes that the list2 has at least as many elements as list one though
for my $i(0..$#list1){ $list1[$i] += $list2[$i]; }
For the non list how about;
my @list2; push @list2, $some_value, $some_other_value, $this_variable, $that_var +iable; for my $i(0..$#list1){ $list1[$i] += $list2[$i]; }
I'm not sure if its really worth it however.

John

Replies are listed 'Best First'.
Re^2: Adding two lists together
by AnomalousMonk (Archbishop) on Nov 05, 2009 at 19:06 UTC
    Another approach to the pesky 'list of scalars':
    >perl -wMstrict -le "use List::MoreUtils qw(each_array); my ($w, $x, $y, $z) = ( 1, 2, 3, 4); my @incs = (10, 20, 30, 40); my $ea_inc = each_array @incs; $_ += $ea_inc->() for $w, $x, $y, $z; print qq{w $w x $x y $y z $z}; " w 11 x 22 y 33 z 44
    Note that nothing is done here to check that the list and the array have the same number of elements!