#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(pp); $|=1; #turn off stdout buffering foreach my $directory (glob "my_data/*") { print "Directory: $directory\n"; my %best4; foreach my $file (glob "$directory/*.txt") { open(my $fh, "<", "$file") or die "Can't open < $file: $!"; while (<$fh>) { statsRound4($fh,\%best4) if /^round is 4/; } close $fh; } dumpBest4(\%best4); #pp \%best4; #uncomment this to see what it does - good tool } sub statsRound4 #add next 4 team lines to stat table #all of these guys made it to Round 4 { my ($fh, $hash_ref) = @_; for (1..4) { my $team_round4 = <$fh>; chomp $team_round4; $hash_ref->{$team_round4}++; } } sub dumpBest4 #print highest keys/values sorted by descending value { my $hash_ref = shift; my @top_teams = sort{my $myA = $hash_ref->{$a}; my $myB = $hash_ref->{$b}; $myB <=> $myA }keys %$hash_ref; foreach my $team (@top_teams[0..3]) { print "$team\t $hash_ref->{$team}\n"; } } __END__ Directory: my_data/03-04-2019-22-09-24 1.va 12 1.duke 12 1.gonzaga 8 1.nc 4 Directory: my_data/03-04-2019-22-14-09 1.duke 9 1.gonzaga 9 1.nc 8 1.va 7 Directory: my_data/03-04-2019-22-14-55 1.gonzaga 10 1.va 7 1.duke 7 1.nc 7 Directory: my_data/03-04-2019-22-16-53 1.va 8 1.nc 8 1.gonzaga 8 2.ky 5 Directory: my_data/03-04-2019-22-20-00 1.gonzaga 9 1.va 9 1.duke 8 1.nc 7 Directory: my_data/03-04-2019-22-21-01 1.nc 7 1.gonzaga 7 3.lsu 6 1.duke 6 Directory: my_data/03-04-2019-22-24-54 1.duke 9 1.va 7 1.nc 7 1.gonzaga 7 Directory: my_data/03-04-2019-22-26-59 1.va 11 1.duke 9 1.nc 8 3.texTech 5 Directory: my_data/03-04-2019-22-28-51 1.duke 12 2.ky 6 1.va 6 1.gonzaga 5
In reply to Re^3: using File::Find to grep for text
by Marshall
in thread using File::Find to grep for text
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |