Re: how to run regex calculation

demerphq <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <CANgJU+V+w6xYtxaKGvtGbNJ=QXCxGJk3hS5JOvBrhRtt2wD_xw@mail.gmail.com>
On Thu, 9 Jan 2020 at 17:25, MIchael Capone <[email protected]> wrote:
>
> It probably won't ever work.

Joseph He's solution works just fine:

perl -le'for my $str ("2 3 6", "1 1 1" ,"1 2 3","123 456 56088"){
print "($str)", $str =~ /(\d+)\s(\d+)\s(??{ $1 * $2 })/ ? " matched" :
" rejected"}'
(2 3 6) matched
(1 1 1) matched
(1 2 3) rejected
(123 456 56088) matched

(??{ ... }) is the recursive/deferred pattern,  it executes code and
then uses the final result as a new pattern that must match at the
current position in the string.

Yves

Yves
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.