Today I had to write a regular expression definitely more complex
than I'm used to do (I'm a real inept: for example this is the
first time I use x modifier in REs :)).
This experience showed me I spent a lot of time trying to make my RE working, specially (in my opinion) 'cause I'm not able to debug it in a good way.
I used some tecniques in order to make my work faster (well, I should say "not so slow"...):
- x modifier. I think the first debug trick is always avoid debug, i.e. write correct code :). And to write correct RE a good trick is comprehend what are you writing. Whitespaces and comments are very good and, last but not least, they let you...
- proceed incrementally. I wrote my code incrementally, commenting large chunks of the regular expression and debugging only small pieces
- prepare case tests instead of using only actual data that will be processed by the RE.
- exploit the isomorphism between RE and state machines. Did you ever simulated by hand your RE (I mean, a "real" RE) using paper, pencil, coins and drawing a state machine? (and using a computer?
- I'd really like to discover there's a way to follow what's happening at "core level" when Perl try to satisfy a RE. This is not very good from my point of view (I think this kind of "insight" perturbs what's happening at core level), but I also think that such a possibility should save me some time this afternoon. Maybe something like this?
What do you think about?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Debugging regular expressions
by wog (Curate) on Jun 21, 2001 at 01:13 UTC | |
(Ovid) Re: Debugging regular expressions
by Ovid (Cardinal) on Jun 21, 2001 at 01:57 UTC | |
Re: Debugging regular expressions
by Abigail (Deacon) on Jun 21, 2001 at 04:22 UTC | |
Re: Debugging regular expressions
by Albannach (Monsignor) on Jun 21, 2001 at 15:07 UTC | |
Re: Debugging regular expressions
by clemburg (Curate) on Jun 21, 2001 at 12:35 UTC | |
Re: Debugging regular expressions
by busunsl (Vicar) on Jun 21, 2001 at 01:16 UTC |
Back to
Meditations