Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Proper creation of a negative number

by toolic (Bishop)
on Jul 08, 2015 at 13:31 UTC ( [id://1133720]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133720]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-24 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found