Hmm. So

koschei on 2002-06-10T23:32:42

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

TorgoX on 2002-06-11T00:27:39

I'm quite happy that people are using Time::Duration for things!

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.

What, no Solaris support?

djberg96 on 2002-06-12T19:31:09

Methinks it's time to write 'uptime' as an extension so us poor slobs using Solaris can use it (no /proc/uptime here). :)

tweak

jdporter on 2002-06-19T04:02:10

How about this tweak (untested):

    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";

Re:tweak

koschei on 2002-06-19T04:41:24

Yes. That's better. (Tested.)