elusion has asked for the wisdom of the Perl Monks concerning the following question:
I am, currently, building a large project, part of which involves a complicated parsing procedure, for which I am hoping to enlist the help of perl's regex engine. However, it is somewhat limited in the area I need help in. Take the following example regex: /(?:(\d)\w))+\d\w/ Not too complicated, but it will be, because if you know your regexes, you know that $1 will only contain the value of the last match. Meaning matching that regex against "1b2b3b4b5b" will result in $1 being equal to 4. There is a way to get to the other values, however. As japhy proposes in his book, the code:
will match and stuff the vars in @vars, though in a somwhat roundabout way. My need goes even further, however, as I need to create these dynamically. I can, and have, done this, with one problem. In order to speed this up, I have tried to use qr//. I am doing this in an OO interface, so that it works well with the rest of my program. But qr// doesn't seem to like the above regex. It doesn't complain, but it somehow messes up other variables in my program. Objects that are in a different module altogether. I don't know how or why, but it is, even though I use warnings, strict, and what I think are good coding practices.my @vars; $string =~ /(?{local @1 = ();} (?:( (\d) (?{ local @1 = (@1, $1) }) \w )+ \d\w (?{ @vars = @1 /x
My question is, why does it do this? When I take the local command out of the regex, everything works, and my other variables aren't messed up. In order to get the speed and interface I want, I need to figure out how to do this. Thank you,
elusion : http://matt.diephouse.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using qr// with a complicated regex
by Chmrr (Vicar) on Jul 12, 2002 at 21:29 UTC | |
by elusion (Curate) on Jul 12, 2002 at 22:59 UTC | |
|
Re: Using qr// with a complicated regex
by BrowserUk (Patriarch) on Jul 13, 2002 at 00:36 UTC | |
by elusion (Curate) on Jul 13, 2002 at 00:48 UTC |