jeevs wrote:
why is it that when i write
my %hash = (jeevan=>'ingale', sarika=>'bere' );
my @arr = @hash{jeevan, sarika};
print @arr;
prints ingale bere ....
can someone explain me how an @sign is used and what exactly goes in
the secongline of thecode.
contrary when i try something like replacing the @ sign in second line
with % sign which seems more logical it doesnt work
my %hash = (jeevan=>'ingale', sarika=>'bere' );
my @arr = %hash{jeevan, sarika};
print @arr;
if any1 can direct me to document .. it would be helpfull
Firstly, /always/
use strict;
use warnings;
after which you wil have to write
my @arr = @hash{'jeevan', 'sarika'};
instead. You will find it resolves a lot of simple problems without you
having to ask for help.
You are using a /slice/ of the hash data. Look at
perldoc perldata
(find for the section titled 'Slices')
If you access a single element of the hash, you use a dollar sign like the
scalar variable prefix:
$hash{'jeevan'}
If you want to access multiple elements at the same time, resulting in a list
of values, you must use an at sign, like the array variable prefix:
@hash{'jeevan', 'sarika'}
using a percent sign, as in %hash{'jeevan', 'sarika'} is meaningless as the sign
in this context doesn't denote a variable type but a mode of accessing the data,
and must be either $ if you're indexing a single element or @ if you want
multiple
elements.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/