Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Reopen file when contents changed?

by blazar (Canon)
on Jun 07, 2005 at 15:31 UTC ( [id://464343]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    
  2. or download this
    while()
    
  3. or download this
    while(1)
    
  4. or download this
    {
       my @loads;
       my $i = my $cpuload = 0;
       open(INFIL,"< /proc/stat") || die("Unable To Open /proc/stat\n");
    
  5. or download this
       <INFIL> =~ /^cpu\s+(\d+)\s+(\d+)\s+(\d+).*/;
       @loads  = ($1, $2, $3);
    
  6. or download this
       my @loads = (<$fh> =~ /\d+/g)[0,1,2];
    
  7. or download this
        local $_=<$fh>;
        (warn "something wrong!\n"), next
          unless /^cpu\b/;
        my @loads = (/\d+/g)[0..2];
    
  8. or download this
       sleep 1;
       seek INFIL, 0, 0;
       <INFIL> =~ /^cpu\s+(\d+)\s+(\d+)\s+(\d+).*/;
       foreach ($1, $2, $3) { $cpuload += $_ - $loads[$i++]; }
       close(INFIL);
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://464343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found