Okay, w/o questioning the idea, some code comments:
Well #1, as always "use strict". You'll be busted 9 ways from Sunday here, but cleaning them up will help you alot. But:
foreach(@sites){ $site=$_; # call the sub &getpages($site); }
seems:
foreach my $site ( @sites) { &getpages($site); }
is a little smoother. You're doing some mixing of your subs and globals: if you open OUTFILE, print @data to it, you should close it. If @data is a global, it probably shouldn't be populated in a sub. It can be but it's not a great coding practice. Subs should work on local, er, "my" data structures and return anything that the main routine needs to use. As in, you're getpages is ref/using the global $site, not the param, so it'd be better as:
sub getpages{ # start timer my $t0 = [gettimeofday]; # get the page my $site = shift; get("$site"); # stop timer my $t1 = [gettimeofday]; # write the values my $elapsed = tv_interval $t0, $t1; &writevalues($elapsed); if($debug){ print "Site $site took $elapsed seconds to load\n"; } } # sub getpages
and notice I took the comment off of your print (print STDERR might be better). That's why you have $debug, though *I* prefer using debug to set various levels so you can have it on for just the code locations you need as in:
if ( $debug > 10 ) { print STDERR "Site $site took $elapased seconds to load\n"; }
Your writevalues should then "my $elapsed = shift;" - yes, seems a bit cumbersome, but it'll help make this a bit more readable to the next monk who's reading your code (of course, you'd add "return $elapsed;" to sub getpages). Hmm, writevalues also seems troubled by the same thing, I guess I'd have put getpages and writevalues in the foreach $site loop in the main rather than have getpages call writevalues. I'd initialize @data w/ the date/time (I think:$data[$[] = scalar localtime; would be one way to get what you want) *before* you started your foreach loop, skip the $space var and put it in your output loop, which'd be:
$data[$[] = scalar localtime; foreach my $site (@sites){ # call the sub my $elapsed_time = &getpages($site); push @data, writevalues($elapsed_time); } open(OUTFILE,">>$datafile") || die "Cannot open $datafile :$!"; foreach $data (@data) { print OUTFILE "$data "; } print OUTFILE "\n"; close OUTFILE;
As for the next part (whoof, I'm tired), well you should probably be sure $samples isn't zero, er.

a


In reply to Re: Testing the network connection by a
in thread Reaped: Testing the network connection by NodeReaper

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.