Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Building Regex Alternations Dynamically

by jo37 (Deacon)
on May 17, 2020 at 09:46 UTC ( [id://11116849]=note: print w/replies, xml ) Need Help??


in reply to Building Regex Alternations Dynamically

It took some time until I discovered this jewel. It's great. Thanks a lot!

One thought about the usage of map: Here it needs to be in list context, which is a bit odd when declaring a scalar. In a version that has two characters more to type this can be avoided:

my $regex = sub { qr/@_/ }->( join '|', map {quotemeta} sort { length $b <=> length $a } @values); print "$regex\n";

Greetings,
-jo

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Replies are listed 'Best First'.
Re^2: Building Regex Alternations Dynamically
by haukex (Archbishop) on May 17, 2020 at 09:53 UTC
    my $regex = sub { qr/@_/ }->( join ... );

    A very nice idea, I like it, thank you! I've added a reference to the node.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2024-04-24 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found