in reply to Tie: Creating Special Objects

Excellent tutorial! The only problem is that I've gotten errors from the regex on three different unixes. I've quadruple-checked my syntax, so i don't think it's that.

the program I'm using with the the module is ...

#!/usr/bin/perl -w use strict; use lib("."); use Uptime; $|++; my $uptime; tie $uptime, 'Uptime'; printf("%20s%-20s\n", "uptime:\t", $uptime->uptime); printf("%20s%-20s\n", "users:\t", $uptime->users); printf("%20s%-20s\n", "load(1):\t", $uptime->load('one')); printf("%20s%-20s\n", "load(5):\t", $uptime->load('five')); printf("%20s%-20s\n", "load(15):\t", $uptime->load('fifteen')); printf("%20s%-20s\n", "string:\t", $uptime->as_string);


... and the output I get on an AIX system, a Solaris system, and a Darwin system, is ...

./dumpuptime.pl uptime: 21 days, 8:02 Use of uninitialized value in printf at ./dumpuptime.pl line 14. users: load(1): 1 load(5): 0.04 load(15): 0.03 string: 20:39pm up 21 days, 8:02, 1 users, load +average: 0.04, 0.03, 0.04


Do I have something wrong, or is the regex in the tutoral off? Thanks, -s-

Replies are listed 'Best First'.
Re: Re: Tie: Creating Special Objects
by btrott (Parson) on Jul 07, 2001 at 10:29 UTC
    I think there are two problems here, both mine. The first is that the regex is slightly wrong. I have now updated it (it was capturing when it should not have been). The second problem is that I named the fields in the Uptime struct incorrectly. They should be one, five, and fifteen, as you have them, but I named them five, ten, and fifteen. This incorrect naming was only in the section where the entire module was presented (not where it was in bits and pieces amidst explanation).

    Thanks for alerting me to these. :)

      thank *you*... the update works great, and the whole tutorial was very informative.