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

Re: Re: Creating regex from arrays

by QwertyD (Pilgrim)
on Jul 30, 2003 at 02:36 UTC ( [id://279056]=note: print w/replies, xml ) Need Help??


in reply to Re: Creating regex from arrays
in thread Creating regex from arrays

I can see that you probably posted this as a TIMTOWTDI alternative to the half-million other posts using join. I would have never thought to do it that way. I wonder: does your method have an advantage over join, or is it just as good?


Once it's Turing complete, everything else is just syntactic sugar.

Replies are listed 'Best First'.
Re: Re: Re: Creating regex from arrays
by Zaxo (Archbishop) on Jul 30, 2003 at 03:08 UTC

    You're right, timtowtdi sitting on my shoulder. I do like that construction, though. IMO, it's more concise and less visually noisy. True, it depends on a trick from the second tier of quote operator details, but I think the sparse notation and localization of $" pretty well telegraph what the trick is.

    I don't know if there is any performance benefit, other than what's obtained from constructing a compiled regex with qr//. That could as well be done with join. I've never benchmarked this.

    A minor refinement of the code, to assign $re where it is declared:

    my $re = do { local $" = '|'; qr/@array/; };
    or, if metacharacters may be a problem,
    my $re = do { local $" = '|'; qr/@{[map {quotemeta} @array]}/; };

    After Compline,
    Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found