Perhaps   ping -t perlmonks.org > ping.log   isn't working because the -t option goes forever until you stop it. So the the file ping.log is never closed. (You might take a look at the -n option.)

You don't make clear if you *need* a log file or if that is just your strategy for accomplishing your analysis.

If you are open to other ways of grabbing the data, you might skip redirecting the results to a file. Consider using back-ticks or qx(...) and then just wait for each run before proceeding. Here's a brief example with a generous sprinkling of intermediate variables for clarity.

#!/usr/bin/perl5 -w use strict; my ($avg_time, $raw_data, @times, $time_count, $total_time); my $repeats = 5; my $addr = 'www.perlmonks.net'; for (my $i = 1; $i <= $repeats; $i++) { $raw_data = `ping $addr`; # NOTE back-ticks # Now do something interesting. We'll just... @times = $raw_data =~ /time=(\d+)/g; $total_time = 0; $time_count = 0; for (@times) { $total_time += $_; $time_count++; } $avg_time = $total_time / $time_count; print "$i. Average time: ${avg_time}ms\n"; }
Which produces:
1. Average time: 61.25ms 2. Average time: 61.75ms 3. Average time: 60.75ms 4. Average time: 62ms 5. Average time: 62.25ms
You could, of course, just collect your data in the larger for loop and then do your analysis on the whole thing after you have collected as many ping responses as you need. Just make sure you don't set the data gathering processes to run forever.   ;-)

In reply to Re: Executing independet commands in PERL by dvergin
in thread Executing independent commands in PERL by FiReWaLL

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.