linux-l: Perl Datum Formatieren

Guido Roock G.Roock at gmx.de
Mo Apr 9 18:20:31 CEST 2001


Hallo,

ich benötige ein Datum im Format "DD.MM.YYYY HH:MM:SS".
Dafür hab ich mir etwas in Perl geschrieben. Jetzt frage
ich mich, ob man das noch verkürzen kann. Mein Source funktioniert
zwar, ist aber sehr lang.

Ja, es muß Perl sein. Es ist nur ein Teil von einem großen Perl-Script.

Hier ist mein Source. Wo kann man kürzen?

#!/usr/bin/perl -w

$now = time;
$timelocal = localtime($now);
&Monat;
@date = split(/ /,$timelocal);

$tag = sprintf("%02d",$date[3]);
$month = sprintf("%02d",$date[1]);
$year = sprintf("%04d",$date[5]);
print "$tag.$month.$year $date[4]\n";

sub Monat
{
        $timelocal =~ s/Jan/1/;
        $timelocal =~ s/Feb/2/;
        $timelocal =~ s/Mar/3/;
        $timelocal =~ s/Apr/4/;
        $timelocal =~ s/May/5/;
        $timelocal =~ s/Jun/6/;
        $timelocal =~ s/Jul/7/;
        $timelocal =~ s/Aug/8/;
        $timelocal =~ s/Sep/9/;
        $timelocal =~ s/Oct/10/;
        $timelocal =~ s/Nov/11/;
        $timelocal =~ s/Dec/12/;
}

Gruß Guido

-- 
Guido Roock
<G.Roock at gmx.de>
http://members.surfline2000.net/roock



Mehr Informationen über die Mailingliste linux-l