Chas. Owens wrote:
On Sat, Feb 7, 2009 at 16:09, Gunnar Hjalmarsson <[email protected]> wrote:
Chas. Owens wrote:
This isn't a job for a regex; it is a job for split:
whose first argument is a regex pattern... ;-)
snip

Yes and a regex follows in the substitute, but the whole things isn't
being done with a regex.  Trying to do it with one regex can lead to a
confusing and fragile mess.

TMTOWTDI

    use Time::Local;
    while (<DATA>) {
        s{,(.+?),}{
            my ($d, $m, $y) = split /\//, $1;
            my $t = timelocal 0, 0, 0, $d, $m-1, $y;
            ($d, $m, $y) = (localtime $t)[3..5];
            sprintf ',%d-%02d-%02d,', $y+1900, $m+1, $d;
        }e;
    }

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to