There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Yes, regular expressions can interpolate variables into them:
You may also decide you don't need a pattern match, and if you can come to that conclusion you avoid the problem of treating strings as code:
You can observe the rules of how interpolation works in regular expressions by reading perlop and perlre. The index function is also documented at perldoc -f index. An advantage of the index approach is that you're not exposing the regular expression mini-language and engine to arbitrary strings, which could contain code. It's also lighter-weight, not invoking the engine. Dave In reply to Re: Can a regular expression include an arbitrary string variable?
by davido
|
|