Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Transform numeric string in numeric string

by spadacciniweb (Deacon)
on Nov 28, 2005 at 16:42 UTC ( #512263=perlquestion: print w/ replies, xml ) Need Help??
spadacciniweb has asked for the wisdom of the Perl Monks concerning the following question:

I would to change a number in an other number as in example:

123456789 -> 123.456.789

Rember I: the input number length can to be whichever.
Remember II: i would to build a regular expression that make this function. I don't want a script as:
while { ... }
but I want a unique line.
thanks.

Comment on Transform numeric string in numeric string
Download Code
Re: Transform numeric string in numeric string
by ikegami (Pope) on Nov 28, 2005 at 16:47 UTC

    What happens if you have 8 characters instead of 9?

    123.456.78:

    $num =~ s/(.{3})(?!$)/$1./g;

    12.345.678 (efficient):

    $num = reverse $num; $num =~ s/(.{3})(?!$)/$1./g; $num = reverse $num;

    12.345.678 using just a regexp (inefficient):

    $num =~ s/(?!^)(.{3})(?=(?:.{3})*$)/.$1/g;
      it's ok:
      $num =~ s/(?!^)(.{3})(?=(?:.{3})*$)/.$1/g;
      thank you!!
Re: Transform numeric string in numeric string
by Fletch (Chancellor) on Nov 28, 2005 at 16:48 UTC

    See perldoc -q "commas added" and adapt.

Re: Transform numeric string in numeric string
by davorg (Chancellor) on Nov 28, 2005 at 16:59 UTC
Re: Transform numeric string in numeric string
by kulls (Hermit) on Nov 29, 2005 at 03:39 UTC
    Try this formatting module for string to number and vice versa.
    -kulls

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://512263]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2014-10-24 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (132 votes), past polls