Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Reusing a complex regexp in multiple spots, escaping the regexp

by ikegami (Patriarch)
on Apr 12, 2026 at 20:11 UTC ( [id://11167525]=note: print w/replies, xml ) Need Help??


in reply to Reusing a complex regexp in multiple spots, escaping the regexp

Use <<'PATTERNEND'. It doesn't allow/require escaping.

my $pat = <<'PATTERNEND'; \s PATTERNEND

<<PATTERNEND, aka <<"PATTERNEND" uses the same quoting rules as double-quote literals, so you'd need to esacape characters that are special in double-quote literals, which includes \.

my $pat = <<PATTERNEND; \\s PATTERNEND
my $pat = <<"PATTERNEND"; \\s PATTERNEND

But qr// is better suited for regex patterns.

my $re = qr/ \s /x;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11167525]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2026-05-11 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.