in reply to I have Wma file jammed in my regex
What follows is an untested but cleaned up version that works incrementally. Were I maintaining this long-term I might declare multiple passes through the log files (one for each type) to be a mistake and I would do one scan for all types at once. But if it is good enough, this is simple.
BTW some points.use strict; #sifts all the server logs based on media type my @servers=('XXXXX','YYYYYYY','ZZZZZZZ'); my $dir1='//workstation/share/directory/'; my @types= qw(mp3 avi mpg mpe wav mov rmj zip exe wma); foreach my $type (@types){ my $total=0; my $out = "$dir1/sifted/$type.txt"; open (OUT, "> $out") or die "Cannot write to '$out':$!"; foreach my $server (@servers){ my $in = "$dir1/$server\.txt"; unless(open IN,"< $in") { warn " Cannot read from '$in': $!"; next; } my $re = qr/\.$type\z/i; # I assume this is what you want? while (<IN>) { chomp; if (/$re/){ # Get filesize my $kbytes = (stat)[7]/1024; if (defined($kbytes)) { $total += $kbytes; print OUT "$_\t$kbytes KB\n"; } else { print OUT "$_\tNOT FOUND\n"; } } } } my $mbytes = $total/1024; print OUT "\n\nTotal: $mbytes MB\n"; print "Finished $type...\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Ran out of OCD meds..
by PiEquals3 (Acolyte) on Jan 19, 2001 at 23:31 UTC | |
by myocom (Deacon) on Jan 19, 2001 at 23:43 UTC |