in reply to Matching string containing values between 0 and 100 inclusive

For educational purpose ( see ""(??{ code })" section of perlre). In real code, please use KISS_principle if ($x >= 0 && $x <= 100).
perl -le ' for $num (qw(-1 0 7 12 88 100 123)) { if ($num=~ /^(\d+)(??{$^N >=0 && $^N <= 100 ? "" : "(?!)"})$/) { print $1; } } '
update: added if clause. update2: added perlre reference.

print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Replies are listed 'Best First'.
Re^2: Matching string containing values between 0 and 100 inclusive
by ikegami (Patriarch) on Mar 17, 2009 at 23:44 UTC

    That compiles a regexp pattern every run.

    /^(\d+)(??{$^N >=0 && $^N <= 100 ? "" : "(?!)"})$/

    should be

    /^(\d+)(?(?{ $^N < 0 || $^N > 100 })(?!))$/

    And match failures would be cheaper still as

    /^(\d+)$(?(?{ $^N < 0 || $^N > 100 })(?!))/