|There's more than one way to do things|
Re: Difference between $1 and \1.by 7stud (Deacon)
|on Dec 27, 2012 at 10:50 UTC||Need Help??|
$str = aa;
Unless you have a variable named aa somewhere, that line will give you an error.
The rule is: $1 is used inside strings and \1 is used inside regexes.
Examine the inputs for the substitution operator:
Here are some examples:
I used the following regex to find repeating characters in a string.
A regex acts like a double quoted string with respect to variable interpolation (and with respect to string escape sequences). $1 has not been assigned a value by a previous match, so $1 is equal to undef. And when undef is used like a string, perl converts it to a blank string. Interpolating undef into a double quoteish context, like your regex, means you are interpolating a blank string, so your regex is equivalent to: /(a)/