Prev: regex inserting a - for every third digit in a number from rightto left
Next: FAQ 3.12 Where can I get perl-mode or cperl-mode for emacs?
From: Tad McClellan on 16 Jul 2010 15:10 lennie <erling.kopperdal(a)lyse.net> wrote: > Hi group! > > Apologies if this is trvial for you, but I try to construct a s/ / /g that > will insert a - for every third digit in a number from right to left, ie: > 123456 -> 123-456 > 1234567 -> 1-234-567 > 123 -> 123 (no - as first char) Start with perldoc -q comma How can I output my numbers with commas added? then: ----------------- #!/usr/bin/perl use warnings; use strict; foreach my $before qw(123456 1234567 123) { my $after = $before; 1 while $after =~ s/^([-+]?\d+)(\d{3})/$1-$2/; print "$before -> $after\n"; } ----------------- -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site. |