Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "$$q" mean in Perl?

Tags:

perl

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?

like image 790
user2870 Avatar asked Apr 06 '13 20:04

user2870


2 Answers

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
like image 104
PSIAlt Avatar answered Nov 06 '22 12:11

PSIAlt


$$q == ${$q}

$q represents a reference, and you are trying to dereference it in scalar context.

For more information, visit the perlref documentation.

like image 42
user1587276 Avatar answered Nov 06 '22 13:11

user1587276