|more useful options|
Read in a regex without having to use string eval?by Argel (Prior)
|on Nov 23, 2011 at 00:49 UTC||Need Help??|
Argel has asked for the
wisdom of the Perl Monks concerning the following question:
In the code below, the first line read in is a RegEx we want to test. What I'm wondering is if there is a way I can eliminate the string eval and just enter the RegEx itself without any additional code on the first line?
I would like to enter the first line in __DATA__ like below, and not have to do a string eval if possible. Is there any easy way to do that?
I know the example regex is pointless -- I'm just using it to illustrate the problem, which is that if I just read the line in normally and do not do a string eval, I get error messages like "Unrecognized escape \Q passed through in regex....". I feel like I'm missing something obvious, so feel free to hit me with a clue stick! (^_^;) (^_^)
Update: To be clear, I started off years ago with this script just reading the line in like I want to, but that breaks things like quotemeta. So I find myself working on this again and I'm wondering if there is a way I can just read it in -- i.e. 'my $regex = shift @data;' and no string eval, and no non-regex code in the first line of ___DATA__?
For the curious, this script is used to test named capture RegEx's for a logging app that uses the PCRE library. Since we have several gigs worth of logs (or probably terabytes by now), testing a RegEx in the app can be painful. This script was intended to allow us to work out most of the kinks in the RegEx before trying to run it in the app.
UPDATE: As ikegami helped me realize, the quotemeta (\Q...\E) is actually Perl code. Knew it was something obvious! Thanks for the help!!
Elda Taluta; Sarks Sark; Ark Arks