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

Re: acccesing an hash

Thread Previous
Paul Lalli
May 28, 2007 04:59
Re: acccesing an hash
Message ID:
On May 28, 1:53 am, (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

         @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

Paul Lalli

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About