Dear Monks,
I don't believe it is possible to make the following code any worse. I've been hacking away at perl for many years but am still less than an amateur.
Could you please take a look and suggest a better way of looping through the data (or avoiding the loop all together). In a worse case, I loop through several thousand lines of the same data 80+ times. Ugly.
This snippet of a larger script is used to draw web posts/reqs and opens for a large number of servers using the wonderful Ploticus graphing program.
@servers is a list of 60+ webservers
@DATA web server data pulled from the DB in 5 minute increments

The server in the DB is identified by a HOSTID so I load %SERVER with all the HOSTIDs. IE $SERVER{WEB1}=1234
----

foreach $server (@servers) { chomp $server; open TMP, ">/tmp/$server.tmp"; $ENV{"FILENAME"} = "/tmp/$server\.tmp"; # SUPER INEFFIECIENT, looping through all of the data for each s +erver. Need to rethink this foreach (@DATA) { ($hostid, $time, $get, $post, $currconn) = split(/\t/); next if ($hostid ne $SERVER{$server}); $time = ((int($time/300))*300)+10800; # Add 3 hours for EST + time ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = loca +ltime($time); $year+=1900; $year = substr($year,2); $mon++; $mon = "0".$mon if ($month < 10); $mday = "0".$mday if ($mday < 10); $hour = "0".$hour if ($hour < 10); $min = "0".$min if ($min < 10); $time = "$mon/$mday/$year\.$hour:$min"; $total = $get+$post; print TMP "$time\t$server\t$get\t$post\t$total\t$currconn\n" +; $total_get{"$time"} += $get; $total_post{"$time"} += $post; $total_conn{"$time"} += $currconn; } close TMP; if (!$ARGV[3]) { `$dir/plbin210/bin/pl $dir/WebHits.pol -o $output_dir/graphs/$server\_ +webhits.gif -gif title="$server Gets, Posts and Opens"`; `$dir/plbin210/bin/pl $dir/WebHits.pol -o $output_dir/graphs/$server\_ +Twebhits.gif -gif -scale 0.50 title="$server $hour:$min"`; }

update (broquaint): changed <pre> to <code> tags


In reply to Super Duper Inefficient by Earindil

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.