in reply to disappearing digit with regex and tr
Before the s///: length = 14 31 2e 32 33 34 2e 35 36 37 2e 08 2c 38 39 1 . 2 3 4 . 5 6 7 . ^H , 8 9 After the s///: length = 11 31 32 33 34 35 36 37 08 2c 38 39 1 2 3 4 5 6 7 ^H , 8 9
Update: It's the \b. \b means backspace in a string literal.
Update: Here's a quickly written solution:
my $num_in = 1234567.89; my ($i, $d) = split /\./, $num_in; $i = reverse($i); $i =~ s/\G(\d{3})(?!$)/$1./g; $i = reverse($i); my $num_out = "$i,$d"; print($num_out, "\n");
|
|---|