letssee has asked for the wisdom of the Perl Monks concerning the following question:
Problem is, the notation of value is not consistent. It can be scientific, decimal or can use m,M,p etc. I need them to be consistent for later use. This is what I didname1=value1 name2=value2 ...
I am wondering if there is a better way to do the operation. It seems wasteful that I read the string again and again for each search and replace.sub exp { #Change all numbers in string to exponental #string has name=value pairs my ($string) = @_; for ($string) { s/\dT\s/e12/g; s/\dG\s/e9/g; s/\dM\s/e6/g; s/\dK\s/e3/g; s/\dm\s/e-3/g; s/\du\s/e-6/g; s/\dp\s/e-12/g; s/\df\s/e-15/g; s/\dn\s/e-9/g; s/=(\S+)\s/sprintf("=%e ",$1)/e; } return ($string); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Doing multiple search and replace operations on a string
by toolic (Bishop) on Feb 20, 2014 at 21:47 UTC | |
by johngg (Canon) on Feb 20, 2014 at 23:06 UTC | |
by letssee (Initiate) on Feb 21, 2014 at 04:21 UTC | |
|
Re: Doing multiple search and replace operations on a string
by Laurent_R (Canon) on Feb 20, 2014 at 21:50 UTC |