in reply to Storing Regex Patterns in Scalars
Both dragonchild and Roy Johnson say that you should be looking at qr// and while I agree, you might want to be careful about how you use it if you're also using regular expression modifiers. For instance,
perl -le '$re = "(hello)"; $_ = "Hello world"; print $1 if /$re/i;'
works just fine, but
perl -le '$re = qr/(hello)/; $_ = "Hello world"; print $1 if /$re/i;'
won't.
You need to put the modifier with the qr// for it to be interpretted correctly. I.e.,
perl -le '$re = qr/(hello)/i; $_ = "Hello world"; print $1 if /$re/;'
Just a note in case it comes up :-)
|
|---|