LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to include a string variable in a regex (Perl) (https://www.linuxquestions.org/questions/programming-9/how-to-include-a-string-variable-in-a-regex-perl-781058/)

MTK358 01-09-2010 10:00 AM

How to include a string variable in a regex (Perl)
 
I am wondering how do you include a string variable as part of a regex in Perl?

GooseYArd 01-09-2010 10:17 AM

You just include the sigil + name in the regex, e.g. $f =~ m/blah$var/

MTK358 01-09-2010 10:21 AM

Quote:

Originally Posted by GooseYArd (Post 3820184)
You just include the sigil + name in the regex, e.g. $f =~ m/blah$var/

Is the 'm' before the regex important?

What if you meant $var literally?

GooseYArd 01-09-2010 10:25 AM

nope I just used the m out of habit. If you want a literal var, just escape the $.

MTK358 01-09-2010 11:23 AM

So /$var/ for $var's value, and /\$var/ for the literal string '$var', right?

GooseYArd 01-09-2010 11:31 AM

righty-o


All times are GMT -5. The time now is 06:44 AM.