user2870
user2870

Reputation: 487

What does "$$q" mean in 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?

Upvotes: 5

Views: 568

Answers (2)

user1587276
user1587276

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

Galimov Albert
Galimov Albert

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

Related Questions