Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Is there any way to put regex modifiers into a variable?

by Discipulus (Canon)
on Mar 11, 2018 at 19:45 UTC ( [id://1210680]=note: print w/replies, xml ) Need Help??


in reply to Is there any way to put regex modifiers into a variable?

Hello,

for sure davies's answer is wiser but maybe you are interested to know that also the feared eval string can accomplish the taske:

perl -e "$opts = 'io'; $rex = eval qq(qr/aka/$opts); print 'match' if +'ALAKAIA' =~ $rex" match

PS infact eval is powerful but dangerous: consider at least to check what was passed in following the good principle never trust user input that can be also read as never trust user or just never trust ;=)

my $opts = $ARGV[0]; die "never trust user input" unless $opts=~/^[msixpodualn]+$/; ...

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found