in reply to Re: Hash not getting updated
in thread Hash not getting updated

I had an issue in my code,that's why i had asked this question and given a small example which was very close to the issue i was facing.And your reply helped me to solve the issue. i feel instead of @hash{ @array } = @array; $hash{@array} = @array ; would be better

Replies are listed 'Best First'.
Re^3: Hash not getting updated
by CharlesClarkson (Curate) on May 03, 2005 at 14:23 UTC

    Have you tried it like that?

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper 'Dumper'; my @colors = qw( white yellow green ); my %hash; $hash{ @colors } = @colors; print Dumper \%hash; __END__

    I get this in perl 5.8.6:

    $VAR1 = { '3' => 3 };

    Perl assumes you want to evaluate the array in scalar context. Better to stick to the same notation everyone else uses for hash slices.

    HTH,
    Charles