Reputation: 487
I was studying Perl, and I came across the code piece below:
print $$q, "\n"
There is a $q
variable that we don’t know exactly what it is. However, we know that when we run this code, it prints "world"
.
So, what can $q
be? What does $$q
mean?
Upvotes: 5
Views: 568
Reputation: 936
$$q == ${$q}
$q
represents a reference, and you are trying to dereference it in scalar context.
For more information, visit the perlref documentation.
Upvotes: 2
Reputation: 7357
In your case $q
is an scalar reference. So $$q
gives you a scalar pointed by reference $q
. Simple example:
$a = \"world"; #Put reference to scalar with string "world" into $a
print $$a."\n"; #Print scalar pointed by $a
Upvotes: 5