Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re4: Applying a RegEx in a variable

by Hofmator (Curate)
on Aug 10, 2001 at 18:47 UTC ( [id://103884]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Applying a RegEx in a variable
in thread Applying a RegEx in a variable

<some code>
Better?
Yes, it's better but it still breaks. Consider e.g. giving the modifiers in a different order (/mi instead of your /im), giving multiple modifiers (/ii is perfectly legal) using different delimiters (m!pattern!) and so on.

I'm not saying that it is impossible to parse this regex construct by hand - but why should want to do that? The eval solution always works - if $RegEx is a legal perl pattern matching operator and you can pass out anything with the construct I explained elsewhere in this thread.

Your solution restricts the number of possible patterns and the ways of providing them. The qr solution suffers from the same problems, only it is less restrictive. And the eval is slow but gives you the whole range of possible pattern matching constructs (even s/// would work) and more (which can become a problem/security concern).

To sum up, without knowing the problem better (where does the $RegEx come from, what should be achieved with it, ...) we cannot tell which solution to favour. And as always, TMTOWTDI :)

-- Hofmator

Replies are listed 'Best First'.
Re: Re4: Applying a RegEx in a variable
by George_Sherston (Vicar) on Aug 10, 2001 at 19:16 UTC
    Hmm. I agree. It really would be mad to proliferate if / else statements to deal with all the different permutations of modifiers!

    Also agree with what you said earlier - eval is the way to go, but only if you don't need the dynamically scoped variables.

    I wonder if future perl releases will allow variables as modifiers -
    $modifier = 'i' # or anything else $string =~ /$regex/$modifier;
    - that would make this problem (and others like it?) a lot easier.

    § George Sherston

Log In?
Username:
Password:

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

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

    No recent polls found