in reply to Add Array values

i tried
use strict; use warnings; use Data::Dumper; my %hash = ( one => [ 1, 2, 4 ], two => [ 5, 7, 9 ], ); my @add = ( 7, 8, 15 ); $hash{one} = [ map { $hash{one}{$_} + $add[$_] } (0 .. $#add) ]; print Dumper \%hash;
but that says "Canīt coerce array into hash at line 13".

why? it assigns an array ref.

Replies are listed 'Best First'.
Re^2: Add Array values
by injunjoel (Priest) on Dec 29, 2004 at 23:16 UTC
    Greetings all,
    small syntax problem.
    try:
    $hash{one} = [ map { $hash{one}->[$_] + $add[$_] } (0 .. $#add)];

    -InjunJoel
    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo