Perldoc variable syntax: $ foo vs $ {foo}

I was just looking at perldocs when I came across this in an example ( http://perldoc.perl.org/perlre.html#Regular-Expressions - see Capture Groups example)

"aa" =~ /${a}/; # True
"aa" =~ /${b}/; # True
"aa0" =~ /${a}0/; # False!
"aa0" =~ /${b}0/; # True
"aa\x08" =~ /${a}0/; # True!
"aa\x08" =~ /${b}0/; # False

I could not find the documentation of what this syntax means.

So what does regex / $ {a} / mean in this context?

+3
source share
2 answers

$ using parentheses avoids the ambiguity of variable names. In this way:

$foo = 'house';
'housecat' =~ /$foo/;      # matches
'cathouse' =~ /cat$foo/;   # matches
'housecat' =~ /${foo}cat/; # matches

Also in the link you provided is a definition for $ a and $ b, but you forgot to copy here.

+2
source

$a $a0. , , . - , ${name}.

+3

All Articles