On Jun 6, Nikola Janceski said:
>$$onediminsional_hash_ref{$key}
>@$onediminsional_array_ref[$index]
The leading sigil denotes the amount of stuff being returned, NOT the data
structure being worked with! It is the {} and [] that determine the data
structure.
@ARRAY = (1 .. 10);
$x = \@ARRAY;
%HASH = (a => 'b', c => 'd');
$y = \%HASH;
print $x->[1]; # 2
print $$x[1]; # also 2
print @$x[1]; # ALSO 2 (the list (2))
print $x->[1,4]; # 5
print $$x[1,4]; # still 5
print @$x[1,4]; # 25 (the list (2,5))
Why is $$x[1,4] '5' instead of ('2','5')? Because the leading $ demands
scalar context inside the subscript, so scalar(1,4) => 4, and $$x[4] is 5.
Likewise with hashes.
print $y->{a}; # 'b'
print $$y{a}; # 'b'
print @$y{a}; # 'b'
print $y->{'a','c'}; # 'd'
print $$y{'a','c'}; # 'd'
print @$y{'a','c'}; # 'bd'
Notice, if you will, that while
print @ARRAY[1];
yields a "@ARRAY[1] better written as $ARRAY[1]" warning,
print @$x_ref[1];
does not.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]