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 triedbut got the same (bad) results.$time2 =~ s/^(\d{2})(\d{2})(\d{2})\.(\d{2}).+?/$1:$2:$3.$4/;
I didn't:
Notice the missing five? .+? is non greedy and matches only what it has to, in this case one single character.#!/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
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 |