Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape a dollar sign inside a variable

Tags:

perl

I have a simple line of Perl

s/$var/'string'/g

The issue is that $var contains a string like jkdlsf$lkjl. Note the dollar sign in the middle. It seems because of this dollar sign the replace is not working. How do I escape this when it is inside a variable?

like image 343
evolution Avatar asked Dec 06 '22 07:12

evolution


1 Answers

Use the \Q quote:

s/\Q$var/'string'/g
like image 196
choroba Avatar answered Jan 04 '23 10:01

choroba