What does "$$ q" mean in Perl?

I studied Perl and I came across a code snippet below:

print $$q, "\n"

There is a variable $qthat we do not know for sure. However, we know that when we run this code, it prints "world".

So what could be $q? What does it mean $$q?

+5
source share
2 answers

In your case $q, a scalar link. Therefore, $$qit gives the scalar specified by the link $q. A simple example:

$a = \"world"; #Put reference to scalar with string "world" into $a
print $$a."\n"; #Print scalar pointed by $a
+5
source
$$q == ${$q}

$q represents the link and you are trying to dereference it in a scalar context.

For more information, visit the perlref documentation .

+2
source

All Articles