in reply to Reopen file when contents changed?
use strict; use warnings; while() { my @loads; my $i = my $cpuload = 0; open(INFIL,"< /proc/stat") || die("Unable To Open /proc/stat\n"); <INFIL> =~ /^cpu\s+(\d+)\s+(\d+)\s+(\d+).*/; @loads = ($1, $2, $3); sleep 1; seek INFIL, 0, 0; <INFIL> =~ /^cpu\s+(\d+)\s+(\d+)\s+(\d+).*/; foreach ($1, $2, $3) { $cpuload += $_ - $loads[$i++]; } close(INFIL); print "$cpuload\n"; }
Tie::File looks interesting, so that might not be the final version ;)
Thanks a lot folks!
--------------------------------
An idea is not responsible for the people who believe in it...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reopen file when contents changed?
by blazar (Canon) on Jun 07, 2005 at 15:31 UTC | |
by calin (Deacon) on Jun 07, 2005 at 15:57 UTC |