For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2006 > Doooh! Nice one (was: replace string with variable)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Doooh! Nice one (was: replace string with variable)
Mirco Wahab

2006-05-29, 8:03 am

Thus spoke Gunnar Hjalmarsson (on 2006-05-29 13:26):

> Okay, new attempt:
>
> s/(\.\d*[1-9])0+\b|\.0*(?!\d)/$1 or ''/eg;


my $text = qq{2000,200.0000,200.,20.010000,.0202,985365,0};
$text=~ s/(\.\d*[1-9])0+\b|\.0*(?!\d)/$1 or ''/eg;
print $text;


=> 2000,200,200,20.01,.0202,985365,0

Looks good!

Regards

Mirco

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com