Are you sure? Try running it... :)
The \d+ is greedy too...
cLive ;-) | [reply] [Watch: Dir/Any] |
Yes, I am sure. I did run it, and it output the wrong answer:
-49.994325
-
It doesn't matter that \d+ is greedy, because .* is greedy and gets to go first. The .* only backtracks far enough to allow the \d+ to match. \d+ can match a single digit, so .* only gives up a single digit. But to get the correct answer, \d+ has to match two digits before the decimal point, not one.
On the other hand, it's okay if $2 only contains one digit before the decimal point, if $1 also contains a single digit before the decimal point:
perl -lp0e'/(\d\.\d+).*(\d\.\d+)/s;$_=$2-$1'
| [reply] [Watch: Dir/Any] [d/l] [select] |