Re: replace string with variable
- From: Lars Haugseth <njus@xxxxxxxxxxxxxxxx>
- Date: Mon, 29 May 2006 12:24:55 GMT
* Mirco Wahab <peace.is.our.profession@xxxxxx> wrote:
|
| Thus spoke aca (on 2006-05-29 12:06):
|
| > Hi, from Spain, I'm new user in perl, I have a problem with regular
| > expression,
| >
| > I dont know how I can replace the zeros on the right of the decimal
| > separator, for example I have a file with some lines of data how this
| > example:
| >
| > 20.1300,20.2500,19.7700,20.2500,985365,0
|
| After criticizing others here, I should
| show up also with some solution ;-)
| (to get some bashes):
As you wish :)
| ...
| my $text = qq{2000,200.0,20.01,.020200,985365,0};
| $text = join ',', map{sprintf "%g",$_} split /,/, $text;
| ...
|
| => 2000,200,20.01,0.0202,985365,0
my $text = qq{123.45678900};
$text = join ',', map{sprintf "%g",$_} split /,/, $text;
print "$text\n";
=> 123.457
(Formatting with %g will round to 6 significant digits by default.)
--
Lars Haugseth
"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer
.
- Follow-Ups:
- Re: replace string with variable
- From: Mirco Wahab
- Re: replace string with variable
- References:
- replace string with variable
- From: aca
- Re: replace string with variable
- From: Mirco Wahab
- replace string with variable
- Prev by Date: Re: replace string with variable
- Next by Date: Re: replace string with variable
- Previous by thread: Re: replace string with variable
- Next by thread: Re: replace string with variable
- Index(es):
Relevant Pages
|