in reply to assigning value of a key in a hash to a variable while dereferencing
Hello pearllearner315,
my $englishlang = %{ $langsref }{$countryid}; # <---- this doesn't wo +rk.
Actually, it does work in Perl versions 5.20.0 and above; but only, in a sense, by accident.
Perl 5.20 introduced a new slice syntax for arrays and hashes. So %{ $langsref }{$countryid} (formerly a syntax error) is parsed as a hash slice (of one hash element), returning the list ('England', 'English'). When this is assigned to the scalar variable $englishlang, it follows this rule:
Binary "," is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C's comma operator. (perlop#Comma-Operator)
So $englishlang contains the value 'English' after the assignment.
jwkrahn has shown the correct dereferencing syntax.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|