Perl $$var -- two dollar signs as a sigil? -
this seems should able google, bing, or ddg, i'm coming empty on everything.
basically, i'm tasked (in part) rewriting set of old perl scripts. not being perl programmer myself, there's learning curve in reading these scripts figure out they're doing, i've hit absolute brick wall lines one:
$comment = $$loc{'description'};
near can tell, right-hand side dictionary, or more precisely it's getting value referenced key 'description'
in said dictionary. what's "extra" dollar sign in front of it?
it looks suspiciously php's variable variables, after scouring search engines, assorted stackexchange sites, , perlvar, can't find indication perl has such feature, let alone how it's invoked. i've turned '$' not valid character in variable name, know $$loc
not merely calling variable happens named $loc
.
what dollar sign doing here?
this alternative form of dereferencing. (and should) written as:
$loc->{'description'};
you'll see same other basic data types:
my $str = 'a string'; %hash = (a => 1, b => 2); @array = (1..4); $strref = \$str; $hashref = \%hash; $arrayref = \@array; print "string value $$strref\n"; print "hash values either $$hashref{a} or $hashref->{b}\n"; print "array values accessed either $$arrayref[0] or $arrayref->[2]\n";
Comments
Post a Comment