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.

Replies are listed 'Best First'.
Re: Transform numeric string in numeric string
by Fletch (Bishop) on Nov 28, 2005 at 16:48 UTC

    See perldoc -q "commas added" and adapt.

Re: Transform numeric string in numeric string
by ikegami (Patriarch) 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 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