in reply to Executing independent commands in PERL
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.
Which produces:#!/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"; }
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. ;-)1. Average time: 61.25ms 2. Average time: 61.75ms 3. Average time: 60.75ms 4. Average time: 62ms 5. Average time: 62.25ms
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Executing independet commands in PERL
by FiReWaLL (Scribe) on Mar 08, 2001 at 13:05 UTC |