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.