Why $-reference possible to Perl array? -
this question has answer here:
i thinking how can refer element in perl array sign $.
minimum code
my @x = @{ $_[0] }; for(my $i=0; $i<$#x; $i++){ print $x[$i]; } you initialize array @x array. print out each item array $x[$i] in loop.
i think bit confusing when initialize array @x , size $#x.
why can refer perl array $x?
because perlish way have sigil denoting type of thing you're working with, rather being part of variable name.
$x scalar, unrelated list @x. $x[1] still scalar - it's element from list @x. (and unrelated $x, because - couldn't pick single element out of single element).
$#x single value (scalar) has $ prefix still.
the same applies hashes. %hash whole hash. $hash{$key} single value hash. , @hash{@some_keys} list of values hash.
Comments
Post a Comment