Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Answer: Using CODEconstant/CODEs in regexes?

by japhy (Canon)
on Aug 11, 2001 at 02:54 UTC ( #104065=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > Using constants in regexes? - Answer contributed by japhy

The /e modifier is for the right-hand side of a s/// only. You might want to just leave out the slashes.
use constant PATTERN => qr/def/; if ($string =~ PATTERN) { ... }
Or, if you need to embed a constant, use the array dereference-reference trick:
if ($string =~ /this@{[ PATTERN ]}that/) { ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-02-27 01:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (376 votes). Check out past polls.