in reply to Regex to match ascending sequence

This works for me

my $regex = qr# (\d) (??{ my $c //= $1 ; ++$c })+ #x; "2345654321" =~ $regex; print $&;

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Regex to match ascending sequence
by ExReg (Priest) on Oct 15, 2015 at 17:27 UTC
    Unfortunately, when I try this on my Perl 5.8, I get a panic: top_env message. I know that it doesn't have the //= operator.
      $c //= $d;
      is just syntactic sugar for various constructs such as:
      $c = defined $c ? $c : $d;
      or
      $c = $d unless defined $c;
      Update: I've just quickly tried on an old VMS platform with Perl 5.8.6 with this regex definition:
      $regex = qr# (\d) (??{ my $c = $1 unless defined $c; ++$c })+ #x;
      it still does not seem to work.
      The Defined-Or operator is best emulated with defined and or

      No idea about scopes in 5.8 , I remember 5.10 (or 5.12 ?) having an issue in this case.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      Try  local our $c;

      Also, 5.8 is too old for experimental regex features

        The local our did not help. You are right about it being too old. Wish it was newer.