Following on from Simon's example of many modules for simple things...
#!/usr/bin/perl -w
use strict;
use Time::Piece;
use Time::Duration;
use IO::File;
my $uptime = do {
my $l = (IO::File->new('/proc/uptime')
or die "No! Can't open!: $!\n")->getline;
$l =~/^(\d[\d.]+)\s+(\d[\d.]+)$/;
$1||die "Invalid uptime!\n";
};
my $now = Time::Piece->new;
my $boot = $now-$uptime;
printf <<"EOF", duration($uptime), $boot->cdate, $now->cdate;
Uptime: %s
Boot: %s
Now: %s
EOF
The question is: is it useful?
(Alternative question is: maybe I should've used more modules?)
[Later edited courtesy jdporter...]
#!/usr/bin/perl -w
use strict;
use Time::Piece;
use Time::Duration;
use IO::File;
my ( $uptime ) = (
IO::File->new('/proc/uptime') or die "No! Can't open!: $!\n"
)->getline =~/^(\d[\d.]+)\s+(\d[\d.]+)$/ or die "Invalid uptime!\n";
my $now = Time::Piece->new;
my $boot = $now-$uptime;
printf <<"EOF", duration($uptime), $boot->cdate, $now->cdate;
Uptime: %s
Boot: %s
Now: %s
EOF
Time::Duration (Score:2)
Re:Time::Duration (Score:2)
Thank you for this module --- it's marvellous. It's one of those things that you think "surely someone's written that". I wrote some code for a friend a few years back and he was surprised at how many lines were needed to nicely format the duration. This module solves that =)
cheers!
(Any sarcasm you read into the above was not put there by me.)
---ict / Spoon
Re:Time::Duration (Score:2)
I will thank TorgoX in advance for what I think this will do and how it will help me. Cool.
What, no Solaris support? (Score:2)
tweak (Score:1)
my( $uptime ) = (IO::File->new('/proc/uptime') or die "No! Can't open!: $!\n")->getline =~
Re:tweak (Score:1)
---ict / Spoon