Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Just another Perl shrine
 
PerlMonks  

Re: Applying a RegEx in a variable

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Applying a RegEx in a variable

You could also eval it directly - depends on your application

# eval returns the value of the last evaluated expression if (eval "\$String =~ $RegEx") { print "Matched"; } else { print "Not matched"; }
However this doesn't provide you with access to the regex variables (like $&, $1, $', ...) as they are dynamically scoped - imagine the eval being a separate block of code.

From your post I'm not sure if you are aware of the difference between eval BLOCK and eval EXPR so I'd suggest reading up on that ...

-- Hofmator

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://103825]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.