[PLUG] perl reading /proc/loadavg
Curtis Poe
cp at onsitetech.com
Thu Mar 21 23:55:38 UTC 2002
----- Original Message -----
From: "Paul Heinlein" <heinlein at attbi.com>
To: <plug at lists.pdxlinux.org>
Sent: Thursday, March 21, 2002 3:43 PM
Subject: Re: [PLUG] perl reading /proc/loadavg
> On Thu, 21 Mar 2002, Randy.Dunlap wrote:
>
> > Yes, I'm aware that I could have done it this way, but it makes no
> > sense to me to have to do this....
>
> OK, I think the trouble lies in the <> operator. Combining read() with
> seek seems to do the trick:
>
> sub do_loadavg {
> seek( LOADAVG, 0, 0 ) or die $!;
> my $loadavg;
> read( LOADAVG, $loadavg, 80 );
> print $loadavg;
> }
>
> I don't know enough about what magic goes on in the <> operation, but I
> imagine that it doesn't know how to reset itself after hitting the end
> of a file.
>
> -- Paul Heinlein <heinlein at attbi.com>
You are correct that the diamond operator doesn't reset after hitting EOF,
but the EOF flag is reset whenever a seek is issued.
Cheers,
Curtis "Ovid" Poe
--
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push at A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift at a;shift at a if $a[$[]eq$[;$_=join q||, at a};print $_,$/for reverse @A
More information about the PLUG
mailing list