in reply to Code in regexp

You might want to read my bug report, and the discussion it triggered at http://bugs6.perl.org/rt2/Ticket/Display.html?id=10040. However, I think Perl is mistaken to think that (??{ }) generates a zero-width assertion.

Here's another way of doing it:

/^(\d)(?{local ($x, $c) = ($^N, 0)}) ((\d)(?(?{$c ++; $^N == $x + $c})|\A))+$/x

Abigail

Replies are listed 'Best First'.
Re: Re: Code in regexp
by demerphq (Chancellor) on Nov 28, 2002 at 19:46 UTC
    Is the local() needed abigail? I was playing with this yesterday and didnt seem to need it.

    --- demerphq
    my friends call me, usually because I'm late....

      No, it's not needed. Just like use strict and my aren't "needed". But if your code happens to have a $main::x, you'll be thankful you used local.

      Abigail

        Er, sarcasm aside, the reason I asked was because the documentation suggested to me that they were automatically localized.

        --- demerphq
        my friends call me, usually because I'm late....

Re: Re: Code in regexp
by Jasper (Chaplain) on Nov 29, 2002 at 11:06 UTC
    Does perl think that (??{ }) generates a zero-width assertion?

    If that is the case, why should the + qualifier behave any differently to the {1,8} qualifier in pg's regex below?

    It's surely a bug that one complains about matching empty string repeatedly, while the other seems to behave as non-zero width.

    Jasper
      Further to this (not that this thread isn't long dead), in Terje Kristensen's latest minigolf competition he came up with this:
      -n $;[map{/./,/[^$&-T]/g}/(?=(.*))/g].=$_}{print@
      Which does funny non zero width things for (?=)
      perl -le 'print for "foo bar"=~/(?=(.*))/g' foo bar oo bar o bar bar bar ar r
      I had no idea this would happen, anyway.

      Jasper