On May 28, 6:53 am, [EMAIL PROTECTED] (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.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to