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

Answer: Using CODEconstant/CODEs in regexes?

( #104065=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > Using constants in regexes? 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/) { ... }

Comment on Answer: Using CODEconstant/CODEs in regexes?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-09-22 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (188 votes), past polls