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?
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
$$q == ${$q}
$q
represents a reference, and you are trying to dereference it in scalar context.
For more information, visit the perlref documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With