Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a script thats gathers cpu(using extract command) info for a numerous servers and prints the output to a file. It makes a file for a cluster thens removes it and then moves on to the next cluster. for example server1 and server2 would be cluster1 and server3 and server4 would be cluster2. I then open the output file and get a average for every hour for the day. The problem I have is when I print the average it prints it twice for each cluster because their is two servers in the cluster when i only need it to print once. Here is my code and example of my output file would look like.
my print would look something like this:sub get_avr { my ($cluster) = @_; open(IN, "$outputfile"); while (<IN>) { foreach my $hour (0 .. 23){ $_ =~ tr/ //s; ($date,$time,$cpu{$hour},$io,$rate,$mem) = split(/ /, $_); if ($time =~ /$hour:00/){ $tmem{$hour} = ($tmem{$hour} + $cpu{$hour}); $cnt{$time}++; $avr{$hour} = ($tmem{$hour} / $cnt{$time}); print "$cluster $time $avr{$hour}\n"; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: printing outside a for loop
by GrandFather (Saint) on May 09, 2006 at 01:53 UTC | |
|
Re: printing outside a for loop
by jwkrahn (Abbot) on May 09, 2006 at 02:31 UTC | |
|
Re: printing outside a for loop
by mildside (Friar) on May 09, 2006 at 01:50 UTC | |
by mildside (Friar) on May 09, 2006 at 06:26 UTC | |
|
Re: printing outside a for loop
by mildside (Friar) on May 09, 2006 at 01:53 UTC |