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.

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"; } } } }
my print would look something like this:
cluster1 00:00 43.45
cluster1 00:00 43.45 (But every hour would be printed)
this is the right infomation but i need it to print once not twice.
Here is what my outputfile would look like for a cluster before i open it:
05/08/06 00:00 51.84 1915510 1061 66.13
05/08/06 01:00 25.67 1255510 648 66.07
05/08/06 00:00 35.56 2077540 739 66.26
05/08/06 01:00 33.91 2262510 718 66.37
and of course their would be more the just the hours of 00:00 and 01:00. thanks for any help sorry for any thing that is miss typed.

In reply to printing outside a for loop by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.