[Melbourne-pm] Extracting a parenthesized fragment from a string

Timothy S. Nelson wayland at wayland.id.au
Fri Sep 11 22:05:59 PDT 2009

On Sat, 12 Sep 2009, Daniel Pittman wrote:

> "Timothy S. Nelson" <wayland at wayland.id.au> writes:
>> On Fri, 11 Sep 2009, Sam Watkins wrote:
>>> On Fri, Sep 11, 2009 at 07:05:45PM +1000, Robert Norris wrote:
>>>> So, what's wrong here? And is there an easier way to do this? Note that
>>>> I'm restricted to Perl 5.6, which sucks as I'd really like to try the
>>>> PARNO stuff that came with 5.10.
>>> I think normal regexps aren't the right tool for this, you can do it
>>> easily in a couple of lines of C, but that method would be somewhat slow
>>> in perl.  But given that you're dealing with IMAP, the network is going
>>> to be a lot slower, so you might as well just do it with a for loop over
>>> the characters and count parentheses, rather than some totally obscure
>>> regexp hack.
>> Incidentally, this is something that Perl 6 will solve.  Because it has
>> grammars.  You could use Parse::RecDescent and an IMAP grammar, but that
>> would be overkill in a P5 situation.  P6 on the other hand... :).
> I am curious why you say that using Parse::RecDescent is wrong with Perl5?
> I consider it likely to be more work than is strictly needed, and perhaps
> difficult to feed a protocol stream rather than a complete text, into, but
> I can't see why it would be any less right than in Perl6.
> Do you mind explaining further?  You obviously see something I don't, and
> I would love to understand what. :)

 	No, I think we're seeing the same thing here.  I agree about feeding 
in the stream -- I had a patch for Parse::RecDescent that made that easy which 
I sent Damian, but I don't know that he ever applied it.

 	I'm assuming that this is something where he has only a small amount 
of text (which may be an invalid assumption), and a pretty good idea of what 
it contains, and yes, Text::Balanced is probably exactly right for this.  I 
basically thought that for something this size, Parse::RecDescent might be 
more hassle than it's worth.  OTOH, it might make it easier to port to Perl 6 
in another 2 years.


| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayland at wayland.id.au    | I am                           |

Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- 
PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-

More information about the Melbourne-pm mailing list