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
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
|
|---|