austinby has asked for the wisdom of the Perl Monks concerning the following question:
my @file = <files*.txt>; my $file; my ($sum, $cti, $avg); my $tmp = "tmp.txt"; foreach $file (@file) { $sum = 0; $cti = 0; $avg = 0; open(FIL,"$file"); open(TMP,">$tmp"); while(<FIL>) { chomp; my ($hd, $md, $tl) = split(/\|/,$_); $sum += $tl; $cti++ } $avg = $sum / $cti; open(FIL,"$file"); while(<FIL>) { chomp; my ($hd, $md, $tl) = split(/\|/,$_); $tl = $tl / $avg; my $tlf = sprintf("%.4f",$tl); print TMP "$hd\|$md\|$tlf\n"; } rename("$tmp","$file"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Batch processing of files
by ikegami (Patriarch) on Feb 11, 2010 at 17:38 UTC | |
by kennethk (Abbot) on Feb 11, 2010 at 17:51 UTC | |
by ikegami (Patriarch) on Feb 11, 2010 at 18:30 UTC | |
by kennethk (Abbot) on Feb 11, 2010 at 18:46 UTC | |
|
Re: Batch processing of files
by toolic (Bishop) on Feb 11, 2010 at 17:39 UTC | |
by ikegami (Patriarch) on Feb 11, 2010 at 18:44 UTC | |
by austinby (Initiate) on Feb 11, 2010 at 19:14 UTC | |
by austinby (Initiate) on Feb 11, 2010 at 20:17 UTC | |
by ikegami (Patriarch) on Feb 11, 2010 at 22:35 UTC | |
|