in reply to Proper creation of a negative number

Use the substitution operator to move a minus sign at the end of the string (if any) to the front of the string:
use warnings; use strict; while (<DATA>) { chomp; s/(.+)-$/-$1/; print "$_\n"; } __DATA__ 1.05 -5.66 7.89-

Outputs:

1.05 -5.66 -7.89

Replies are listed 'Best First'.
Re^2: Proper creation of a negative number
by Anonymous Monk on Jul 08, 2015 at 17:12 UTC
    Maybe with a regex that is slightly better at finding numbers, e.g. [.0-9]+\- versus 'anything-at-all' that is followed by a minus sign. Seems that the regex as writ could slurp up everything until the first minus.