CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
substitution

 



mauto
User

Apr 15, 2003, 7:12 AM

Post #1 of 4 (268 views)
substitution Can't Post

In the following string: 5.671.234,56

I want to substitute the dot with a blank and the comma with a . to end up with: 5671234.56


Code
 
$_ = "5.671.234,56";

s/\.//g;
s/\,/./g;

print $_;


This seems to work but can it be handled in one line ?


davorg
Thaumaturge / Moderator

Apr 15, 2003, 7:31 AM

Post #2 of 4 (265 views)
Re: [mauto] substitution [In reply to] Can't Post


Code
tr/.,/ ./;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


mauto
User

Apr 15, 2003, 7:37 AM

Post #3 of 4 (261 views)
Re: [davorg] substitution [In reply to] Can't Post

but this gives: 5 671 234.56

How can i get rid of the spaces ?


davorg
Thaumaturge / Moderator

Apr 15, 2003, 7:47 AM

Post #4 of 4 (260 views)
Re: [mauto] substitution [In reply to] Can't Post

Sorry. I misread your requirements.

Code
tr/,././d;


See the documentation on tr///.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives