Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Feature Idea: qr//e

by vr (Curate)
on Jan 19, 2017 at 09:50 UTC ( [id://1179900]=note: print w/replies, xml ) Need Help??


in reply to Feature Idea: qr//e (updated with solutions)

my $regex = qr{(??{ join '|', map {quotemeta} qw/. | %/ })};

No? Plus, it's eval'ed "before parsing a regex", while s///e is not about it at all.

Replies are listed 'Best First'.
Re^2: Feature Idea: qr//e (updated)
by haukex (Archbishop) on Jan 19, 2017 at 12:00 UTC

    Hi vr,

    my $regex = qr{(??{ join '|', map {quotemeta} qw/. | %/ })};

    Another excellent idea, thank you! I've updated my root node.

    it's eval'ed "before parsing a regex", while s///e is not about it at all

    Yes, you're right, it was misleading of me to write that qr//e would be "analogous to s///e", since in s///e it's the replacement part that gets evaled, not the regex.

    Update: Your solution has the interesting feature that the code gets reevaluated every time:

    use Test::More; my @values = qw/abc def/; my $re = qr{^(??{ join '|', map {quotemeta} @values })$}i; like 'ABC', $re; like 'DEF', $re; unlike 'GHI', $re; push @values, 'ghi'; like 'ABC', $re; like 'DEF', $re; like 'GHI', $re; done_testing;

    Thanks,
    -- Hauke D

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-06-18 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.