Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by LanX (Saint)
on Apr 13, 2026 at 22:29 UTC ( [id://11167537]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Reusing a complex regexp in multiple spots, escaping the regexp
in thread Reusing a complex regexp in multiple spots, escaping the regexp

> I added some /i flags to the numeric patterns.

please note you can also use qr//x to make the sub-terms more readable

> I was surprised that I had to escape the slashes

Well Quote-like-Operators can chose the delimiter freely.

like qr~~ or qr{}

> I used your suggestions

Well ... mainly AI suggestions ;-)

Some were good, others not to my taste.

TIMTOWTDI ...

Here my take

{ my $HEX = qr/ [0-9A-F] /xi; my $HEX_X = qr/ [0-9A-FX] /xi; my $H_opt = qr/ [h]? /xi; my $INT = qr/ \b INT \s? $HEX{2} [hH]? /x; # is longer $H_opt + better ??? our $hyperlinkpattern = qr~ ... $INT ... ~x; }

Please note how the helper variables are restricted to the scope and how $HEX{2} is NOT interpreted as a hash-lookup (surprised me!).

Hope my suggestions helped you having better maintainable code :-)

There are many more improvements which come to mind but I'm prone to over-engineering and it's in you're in a better position to decide what works best for you =)

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (1)
As of 2026-05-10 21:17 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.