in reply to A would-be simple substitution...

Shouldn't the substitution of $time2 work? IE -- see two digits after the '.' and then leave it at that?

No ;-), because you are substituting the matching part, and the trailing digits do not match, they are therefore left alone.

I even tried
$time2 =~ s/^(\d{2})(\d{2})(\d{2})\.(\d{2}).+?/$1:$2:$3.$4/;
but got the same (bad) results.

I didn't:

#!/usr/bin/perl # # use strict; use warnings; my $time2 = "123456.745768"; $time2 =~ s/^(\d{2})(\d{2})(\d{2})\.(\d{2}).+?/$1:$2:$3.$4/; print "$time2\n"; __END__ 12:34:56.74768
Notice the missing five? .+? is non greedy and matches only what it has to, in this case one single character.

take away the ?, and it does, what you want; I'd change the . (dot) to \d and the + to a * though, resulting in

s/^(\d{2})(\d{2})(\d{2})\.(\d{2})\d*/$1:$2:$3.$4/;

regards,
tomte


Hlade's Law:

If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.

Replies are listed 'Best First'.
Re: Re: A would-be simple substitution...
by GaijinPunch (Pilgrim) on Mar 02, 2004 at 08:53 UTC
    See -- told you it was a long day. :) A cold AND jet lag are a losing combination. I can't tell if I'm about to pass out b/c I'm sick, or my body is just out of whack.

    Thanks guys.