I am calling my programm from perl and getting the output with:
$output = `$calling 2>>bla.txt`;
Now I need just a specific value that will be presented in the output which I can check with Regex.
The needed output is:
Distance from Segment XY to its Centroid is: 3.455564713591596
Where XY is any number, and I just match for the “to its Centroid is: ” the following:
if( $output =~ m/\sto\sits\sCentroid\sis:\s(\d)*$/)
But how do I get only the value that is presented near to the end?
I just want it to be printed on the screen.
Any advice?
You print the number you captured in the regex with the parentheses:
You also make sure that the regex can pick up a number with a decimal point, and I’ve allowed an optional sign, too. If you need to worry about optional exponents, add
(?:[eE][-+]?\d+)?after the\d+in my regex.If you have other things to do with the value, then convert into a regular
ifstatement: