In the spirit of TIMTOWTDI, you could also disable metacharacter processing using "\Q..\E":
my $txt = '1,2';
$txt=~ s/(\d+)\,(\d+)/$1\Q0\E,$2/;
This converts the "1" to "10".
Unfortunately, simply escaping like "\0" does not work for many cases, because many escape sequences have special meaning .. Eg: \0 starts an octal sequence. See "perldoc perlrebackslash"
"I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
-- Dr. Cox, Scrubs
| [reply] [d/l] |
In this case I wouldn't use '\Q' at all, since it has an effect while '\E' is quite neutral!
DB<100> $var=666
=> 666
DB<101> "$var\Efoo"
=> "666foo"
DB<102> "$var\Ef\Eoo"
=> "666foo"
Anyway the use case is restricted to interpolation like in qq{} or regex.
Curlies can be used for any variable.
Cheers Rolf
( addicted to the Perl Programming Language)
| [reply] [d/l] |
Thank you for your reply as well :)
Quite interesting way to avoid that problem.
Btw, I was using escape characters before, but like you pointed it's not working for many cases, so I finally decide to ask for Perl Wisdom to do it right :)
| [reply] |
You're welcome! =)
BTW it's not a stupid questions, many allowed (though exotic) variable names are only accessible if surrounded by curlies ...
Cheers Rolf
( addicted to the Perl Programming Language)
| [reply] |
And huge thanks for update! :)
I was searching for something like that before asking my question and even after your answer without any useful results (most likely I just wrongly formulate my request).
| [reply] |
> (most likely I just wrongly formulate my request).
Again, don't worry! =)
After fruitless searching in perlvar and perlsyn I just did a googlesearch for perldoc variable curly braces name which led me to perldata
As you can see I already needed to know the answer to find it quickly ...
Cheers Rolf
( addicted to the Perl Programming Language)
update
Of course in hindsight perldata is the right place to look for variable syntax
| [reply] |