in reply to Re: Calculating variable {n} in regex match
in thread Calculating variable {n} in regex match

FWIW:

>perl -wMstrict -le "my $s = '123 234 3456789 3210 34567'; ;; my @m = $s =~ m{ \b ((\d) (??{ qr{\d{$^N}} })) \b }xmsg; print qq{@m}; ;; my $i = 2; @m = $s =~ m{ \b (??{ ++$i; qr{\d{$i}}; }) \b }xmsg; print qq{@m}; " 234 2 3210 3 123 3456789

Replies are listed 'Best First'.
Re^3: Calculating variable {n} in regex match
by atreyu (Sexton) on Jun 14, 2012 at 14:02 UTC
    okay, AnomalousMonk, this works:
    # the original number of integers to test (will be one-upped) my $i = 1; # the input string to be tested (a number) my $foo = shift; # see if the input string is a two-digit number my $rc = ($foo =~ m{ \b (??{ ++$i; qr{\d{$i}}; }) \b }xmsg) ?'Y' :'N';
    very clever...thanks.

      But sometimes cleverness can be a curse, so you may want to reserve your thanks until later.