Regex teaser

Smylers Smylers at stripey.com
Thu Dec 5 15:07:20 GMT 2013


Yesterday I wrote:

> Paul Makepeace writes:
> 
> > On Tue, Dec 3, 2013 at 5:03 PM, Mark Fowler
> > <mark at twoshortplanks.com> wrote:
> > 
> > > On Tue, Dec 3, 2013 at 6:54 PM, Paul Makepeace <paulm at paulm.com>
> > > wrote:
> > >
> > > > $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a'
> > >
> > > This is where tools like Regexp::Debugger shine.  Running
> > >
> > >  perl -le 'use Regexp::Debugger; ($a = "aabbb") =~ s/b*$/c/g; print $a'
> > >
> > > Shows exactly why it gives the output it does (if you hit "n" for
> > > next a lot)
> 
> Except that gives 3 matches — 15 steps to match “bbb”, then 5 steps to
> match at the end the string, then another 5 steps to match at the end
> of the string a second time. Yet it only prints 2 “c”s.
> 
> Am I interpreting that wrongly? Is this a bug in Regexp::Debugger that
> should be reported?
> 
> > Can't use an undefined value as an ARRAY reference at
> > /Library/Perl/5.16/Regexp/Debugger.pm line 499.
> 
> Ditto, after it's finished. I'll report that bug once I've sent this
> mail.

Thank you to Damian Conway, the module's author, for diagnosing and
fixing this within hours: Regexp::Debugger 0.001018 is now on Cpan.

As well as no longer crashing, it now only reports two successful
matches in the above one-liner.

Smylers
-- 
The UK gov's proposed gagging law will suppress protest and campaigning by
charities and political groups. Read more: http://civilsocietycommission.info/
Please sign this petition: http://38d.gs/1cJ9ViA
Oxfam • BHA • Quakers * Countryside Alliance • League Against Cruel Sports • CND



More information about the london.pm mailing list