Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

IE @hashes = ( { name=>'bob', age=>27} , { name=>'charlie', age=>29} );
%hash1 = $hashes |0|;
It doesnt seem to work for me
  • Comment on If I have an array of hashes, how can i store one into a variable?

Replies are listed 'Best First'.
Re: If I have an array of hashes, how can i store one into a variable?
by snowcrash (Friar) on Apr 17, 2001 at 11:28 UTC
    it doesn't work because you don't have an array of hashes, but an array of references to hashes. arrays can only contain scalar values in perl.
    to get the hash the first element of the array refers to, use my %hash1 = %{ $hashes[0] };
    checkout perldata, perlref, perllol etc.

    cheers
    snowcrash //////
Re: If I have an array of hashes, how can i store one into a variable?
by Beatnik (Parson) on Apr 17, 2001 at 13:09 UTC
Re (tilly) 1: If I have an array of hashes, how can i store one into a variable?
by tilly (Archbishop) on Apr 17, 2001 at 17:11 UTC