develooper Front page | perl.perl5.porters | Postings from August 2000

Re: Proposal for \v and \V, the small- and large- cut regex operators.

From:
Jeremy D. Zawodny
Date:
August 8, 2000 23:10
Subject:
Re: Proposal for \v and \V, the small- and large- cut regex operators.
Message ID:
20000808214522.B17367@peach.zawodny.com
On Wed, Aug 09, 2000 at 02:05:22AM +0000, Simon Cozens wrote:

> You'll note that while the backtracking explanation gives us a clear
> picture of how the regular expression is executed by Perl, the
> combining pieces model is far more useful when it comes to actually
> *writing* regular expressions. When you're thinking about how *you*,
> as a human being, would look for the match in the string, you don't
> think about going all the way to the end of the string and then
> backing up. You look for three distinct chunks - "foo", lots of
> stuff, "bar" - and so when you're programming, you state three
> distinct chunks. Easy.

Agreed, mostly.

I agree that when writing regular expressions it's useful to think in
terms of combining pieces together. Our brains tend to look at things
that way. It just feels natural to think about the beginning and
ending states and not think too much about what happens in
between--especially we you think you know what's going to happen. :-)

> So a backtracking explanation doesn't really help you construct a
> regular expression yourself, in the same way that the combining
> pieces model doesn't tell you how the regular expression is
> executed.

Yes, but what about *debugging* regular expressions? Often times, the
process of constructing regular expressions (complex ones, at least)
is composed of testing and debugging those regular expressions. It's
an iterative process much of the time--much like programming (strange,
eh?)

But when it comes time to figure out why your regular expression
doesn't work in all cases that it should, you often need to resort to
backtracking to really understand why. And that means the user has to
understand what's going on under the hood.

If I understand his comments, Ilya says that he can change things in
such a way that that the hood can be welded shut. That's be
excellent. Hopefully he's describe that work more. Or just send in
patches that do the work. :-)

But what can be done in the meantime?

Someone might try cloning perlre.pod and removing all the references
to backtracking (there we around 15 or 20 I think) and replacing them
with the "combining pieces" equivalent? Or maybe just a replacement
for the ``Backtracking'' section...

That would seem to go a long way toward moving this discussion along.

Jeremy
-- 
Jeremy D. Zawodny                Web Geek, Perl Hacker, Yahoo!
http://www.wcnet.org/~jzawodn/   Jeremy@Zawodny.com



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About