Re: how to run regex calculation

2020-01-12 Thread Paul B. Henson
On Thu, Jan 09, 2020 at 10:36:19AM +0800, Wesley Peng wrote: > $str = "2 3 6"; > > I want to match with: > > true if $str =~ /(\d+)\s(\d+)\s($1*$2)/; > > that's to say, the thrid column would be (firstCol * SecondCol). > > How to write regex for this? I don't think you can do it directly in t

Re: how to run regex calculation

2020-01-12 Thread Alex Mestiashvili
I am not subscribed to the list, so sending to the authors too. This seem to work: echo "2 3 6" |perl -Mstrict -pE 's{(\d+)\s(\d+)\s(\d+)}{my $r="false";$r="true" if $3 == eval"$1*$2";$r}e;' perl -Mstrict -lE 'my $str = "2 3 7"; $str =~ s{(\d+)\s(\d+)\s(\d+)}{my $result="false";$result="true