Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: qr// and user provided regex patterns...

by misterMatt (Novice)
on Jul 31, 2009 at 19:58 UTC ( #784983=note: print w/replies, xml ) Need Help??


in reply to Re: qr// and user provided regex patterns...
in thread qr// and user provided regex patterns...

Using the eval works great for matches : $pattern = eval "qr$pattern" or die $@;
But of course, when I do a 'substitution pattern' s///, it fails because it looks like eval "qrs/stuff/morestuff/. So I tried adding a bang, to wrap around the interpolated variable in the original : $pattern = eval "qr!$pattern!" or die $@; But now my patterns fail to match anything. Example:
s/Bill Clinton/The ex-President/gi on Bill Clinton is the ex-President +. bill clinton. results in Failure.

Replies are listed 'Best First'.
Re^3: qr// and user provided regex patterns...
by ikegami (Pope) on Aug 04, 2009 at 23:53 UTC

    Using the eval works great for matches : $pattern = eval "qr$pattern" or die $@;

    No, it doesn't.

    First of all, it doesn't work at all if $pattern actually contains a pattern.

    And then there are issues with improper escaping. If you pass /a\+/, it won't match "a" followed by "+" as desired.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://784983]
help
Chatterbox?
[Corion]: erix: Yes, but that's mostly for skipping characters you'll never read, but this approach skips the problem of needing to load more data while looking at a half-match
[Corion]: I mostly wonder how I can add this "reversal" to my toolchest, and if it's worth it or just clever
[choroba]: It should greatly simplify the parsing code, no flags or additional reading of the next buffer needed
[Corion]: choroba: Yeah, that's why I like that approach; it seems even quite obvious in retrospect to me, but many things are in hindsight ;)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2016-12-06 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (109 votes). Check out past polls.