Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird $ behavior: ${\string}

Tags:

perl

While I was experimenting, I found out that

print ${\string}

would print string to the screen.
Is this normal? Does this have a name?
like image 950
xyvab Avatar asked Aug 12 '13 21:08

xyvab


2 Answers

The bareword "string" is being understood as a string you simply didn't quote. use strict would prohibit this, and use warnings would have complained about it.

You are then taking a reference to the string (effectively, my $ref = \"string";), and dereferencing it (effectively, ${$ref}).

It is "normal" in the sense that life without strict is sometimes both slippery and sharp-edged.

like image 88
pilcrow Avatar answered Nov 18 '22 07:11

pilcrow


It's a reference to string being dereferenced with ${}

perl -MO=Deparse -e "print ${\string}"
print ${\'string';};
like image 26
mpapec Avatar answered Nov 18 '22 07:11

mpapec