Hello Guys,
 More Perl Style lessons for me, if anyone wants to chip in. Following
is the script on the chopping block today - in the comments the parts
that I did not manage to "elegantize" as much as I wanted.


use Term::ANSIColor  qw(:constants);
use strict;
 
#----------------CONFIGURATION--------


my $timelen = 3;

my @commands = ( '/bin/netstat -ape | /usr/bin/wc -l',
                 '/usr/bin/lsof | wc -l',
                 '/bin/ps ax -L | wc -l' );

my @triggers = qw( 0 0 0);

#-------------------------------------
 
for(my $flag = 1; $flag;) #hate truth as a number...
 {
  my $date = `/bin/date -R`; #three lines seem much for this - any more
elegant way to chomp things up?
  chomp $date;
  print $date."\t\t";
 
  for (my $i = 0; $i < @commands; $i++)
   {
    my $cmd = $commands[$i]; #I don't like these lookups, but I don't
see how to foreach this one
    my $trig = $triggers[$i];
 
    my $result = `$cmd` or die ("could not execute command".$cmd."\n");
    chomp $result;
    $result == $trig  ?  print ON_RED, $result, RESET  :  print $result;
print "\t";
     
    $flag = 0 if ($result == $trig); # finish the internal round,
terminate the external. Any nicer way to do it ?
   }
   
  print "\n";
 }


Hum - the mail client is insisting in wrapping at 80-chars - usually
nice but very appropriate to mess up things here :D

 best - Federico



_________________________________________
-- "'Problem' is a bleak word for challenge" - Richard Fish
(Federico L. Lucifredi) - http://www.lucifredi.com



 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to