develooper Front page | perl.beginners | Postings from May 2007

Re: acccesing an hash

Thread Previous | Thread Next
From:
eishbut@googlemail.com
Date:
May 28, 2007 17:26
Subject:
Re: acccesing an hash
Message ID:
1180370450.641312.10020@p77g2000hsh.googlegroups.com
On May 28, 6:53 am, jeevan.ing...@gmail.com (Jeevs) wrote:
> my %hash = (jeevan=>'Ingale', Sarika =>'Bere');
> my @star = @hash{jeevan, Sarika};
> print @star;
>
> this prints ingale and bere but when i write

Like Paul said, the hash is being treated as an array slice returning
the values for "jeevan" and "Sarika".

>
> my %hash = (jeevan=>'Ingake', Sarika =>'Bere');
> my @star = %hash{jeevan, Sarika};
> print @star;
>

The array assignment line produces an error cos the syntax is telling
perl to unwind the entire hash (key-value pairs) but you're passing
keys to hash which under normal use will return the values. To get the
key-value pairs into @star use:

my @star = %hash;

@star will now contain the key-value pairs (Sarika, Bere, jeevan,
Ingake) but the pairs wont be in any particular order.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About