Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: On the regex pattern variable to be inserted into another

by BillKSmith (Monsignor)
on Feb 10, 2022 at 00:10 UTC ( [id://11141299]=note: print w/replies, xml ) Need Help??


in reply to On the regex pattern variable to be inserted into another

I suspect that you have a regex with a fixed a variable part.
use strict; use warnings; my $string = 'title: ABC_II'; foreach my $index (qr/I/, qr/II/, qr/III/) { print "Match\n" if $string =~ m/ABC_$index/; }

You want to know if you can speed it up by pre-compiling the fixed part.

use strict; use warnings; my $string = 'title: ABC_II'; my $fixed = qr/ABC_/; foreach my $index (q(I II III)) { print "Match\n" if $string =~ m/$fixed$index/; }

Clearly the syntax is allowed. You would have to benchmark your case to find out if and how much it helps.

Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found