Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex to match the following
by wfsp (Abbot) on May 08, 2007 at 10:59 UTC | |
output:
Also out of curiosity, do monks really prefer having the and at the begining of the line? | [reply] [d/l] [select] |
by jimt (Chaplain) on May 08, 2007 at 14:55 UTC | |
Also out of curiosity, do monks really prefer having the and at the begining of the line? Most definitely. It's easier to comment out a conditional to flip it off for debugging purposes, or if you just decide you don't want it any more. One comment at the start of the line and I'm finished. The only remotely tricky thing that pops up is for the last conditional in a block, because that one'll have the semicolon at the end. Solution in that case? ;#. Not quite as clear for the poor sap who maintains it after it's commented that way, but still easy to type. | [reply] |
by kyle (Abbot) on May 08, 2007 at 14:30 UTC | |
Also out of curiosity, do monks really prefer having the and at the begining of the line? I do. Those boolean operators are a lot like control flow statements (e.g., next) because they control whether different parts of the expression are evaluated. I like to have them out front, clearly visible. That way I can more easily tell what might run and what might not. | [reply] [d/l] [select] |
|
Re: regex to match the following
by Krambambuli (Curate) on May 08, 2007 at 08:50 UTC | |
However, you'll probably need to know some more details about the input: can you rely on getting the params always in lowercase, do you get one meta_parameter per input line, etc. | [reply] [d/l] |
|
Re: regex to match the following
by jettero (Monsignor) on May 08, 2007 at 11:04 UTC | |
Honestly, I think the simplest solution is XML::XPath.
For regulars of this type, I usually multi-stage it so I can be sure I matched the right thing.
-Paul | [reply] [d/l] [select] |
|
Re: regex to match the following
by jesuashok (Curate) on May 08, 2007 at 08:57 UTC | |
| [reply] [d/l] |
|
Re: regex to match the following
by cool (Scribe) on May 08, 2007 at 09:20 UTC | |
Hope this small piece would of some help...Because your file has uniform pattern so without regex also this can be tackled
But as always "There's more than one way to do it" n better also :) | [reply] [d/l] |
by johngg (Canon) on May 08, 2007 at 10:52 UTC | |
Cheers, JohnGG | [reply] |
|
Re: regex to match the following
by Jenda (Abbot) on May 09, 2007 at 13:41 UTC | |
Assuming the file is XML, what about something like:
This is much safer than trying to parse the file with regexps. | [reply] [d/l] |