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

Re: acccesing an hash

Thread Previous
From:
Paul Lalli
Date:
May 28, 2007 04:59
Subject:
Re: acccesing an hash
Message ID:
1180353067.215241.103020@p77g2000hsh.googlegroups.com
On May 28, 1: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
>
> my %hash = (jeevan=>'Ingake', Sarika =>'Bere');
> my @star = %hash{jeevan, Sarika};
> print @star;
>
> its an error..
>
> Can someone explain or atleast point me to any document explainng what
> exactly happens heres...

perldoc perldata

     Entire arrays (and slices of arrays and hashes) are denoted
     by '@', which works much like the word "these" or "those"
     does in English, in that it indicates multiple values are
     expected.

         @days               # ($days[0], $days[1],... $days[n])
         @days[3,4,5]        # same as ($days[3],$days[4],$days[5])
         @days{'a','c'}      # same as ($days{'a'},$days{'c'})

     Entire hashes are denoted by '%':

         %days               # (key1, val1, key2, val2 ...)


Basically, you can't just make s*** up and expect it to work.
Whatever gave you the idea that '%hash{jeevan, Sarika}'  was legal
syntax?

Paul Lalli


Thread Previous


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