Thread Hash als Option missbrauchen (118 answers)
Opened by bloonix at 2005-12-19 02:24

steffenw
 2005-12-20 20:48
#60997 #60997
User since
2003-08-15
692 Artikel
BenutzerIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
     my @tm = localtime(time);

    $tm[4] += 1;
    $tm[5] += 1900;

    foreach (@tm) {
       $_ = "0$_" if $_ < 10;
    }

    $stats->{TimePoint}->{Date} = "$tm[5]-$tm[4]-$tm[3]";
    $stats->{TimePoint}->{Time} = "$tm[2]:$tm[1]:$tm[0]";

oder
Code: (dl )
1
2
3
4
5
     my @tm = (localtime)[reverse 0..5]; # time ist default, gleich richtig für spätere Array-Slices sortieren
    $tm[0] += 1900;
    $tm[1]++;
    $stats->{TimePoint}->{Time} = sprintf '%02d:%02d:%02d', @tm[0..2];
    $stats->{TimePoint}->{Date} = sprintf '%04d-%02d-%02d', @tm[3..5];


copy and past
Code: (dl )
1
2
3
4
5
6
 $stats->{SysInfo}     = SysInfo()   if $param{SysInfo};
 $stats->{MemStats}    = MemStats()  if $param{MemStats};
 $stats->{SockStats}   = SockStats() if $param{SockStats};
 $stats->{DiskUsage}   = DiskUsage() if $param{DiskUsage};
 $stats->{LoadAVG}     = LoadAVG()   if $param{LoadAVG};
 $stats->{Processes}   = Processes() if $param{Processes};

oder
Code: (dl )
1
2
3
4
for (qw/SysInfo MemStats SockStats DiskUsage LoadAVG Processes/) {
 no strict 'refs';
 $stats->{$_}  = &$_() if $param{$_};
}

und so weiter.

copy and past ist nicht Perl. Das machen alle die anderen, weil sie von der Programmiersprache allein gelassen werden.

Versuch's noch mal dahin zu optimieren, man wird nicht dümmer davon.\n\n

<!--EDIT|steffenw|1135104812-->
$SIG{USER} = sub {love 'Perl' or die};

View full thread Hash als Option missbrauchen