in reply to Transform numeric string in numeric string

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;

Replies are listed 'Best First'.
Re^2: Transform numeric string in numeric string
by spadacciniweb (Curate) on Nov 29, 2005 at 08:46 UTC
    it's ok:
    $num =~ s/(?!^)(.{3})(?=(?:.{3})*$)/.$1/g;
    thank you!!