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
#!/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
Re:Time::Duration
koschei on 2002-06-11T00:51:28
Ah yes - my apologies; I forgot.
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.)Re:Time::Duration
gizmo_mathboy on 2002-06-11T00:55:42
Wow! That simplifies a script I wrote to calculate resolution and response time for customer ticket.
I will thank TorgoX in advance for what I think this will do and how it will help me. Cool.
Re:tweak
koschei on 2002-06-19T04:41:24
Yes. That's better. (Tested.)