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