| File | Word | Count |
| ..file1.. | ..word1.. | ..count.. |
| ..file1.. | ..word2.. | ..count.. |
...
| ..file1.. | ..wordn.. | ..count.. |
| ..file2.. | ..word1.. | ..count.. |
| ..file2.. | ..word2.. | ..count.. |
... ... ...
| ..filem.. | ..wordn.. | ..count.. |
####
# We'll build the table rows in this array, and we'll
# put in the table headings first
my @tbl_rows = ( th( ['File', 'Word', 'Count'] ) );
for my $digit (0 .. 9) {
for my $file (<$digit*>) {
open (my $FILE_HANDLE, '<', $file) || die "Can't open $file: $! \n";
while (<$FILE_HANDLE>) {
chomp;
my ($word, $count) = split / /, $_;
if ($word =~ /^$search_term$/) {
# Next, we'll convert your print statement:
#print "At $file $word had $count points.", p;
# into code to store a row of data into the array:
push @tbl_rows, td( [$file, $word, $count] );
}
}
close ($FILE_HANDLE);
}
}
# Then turn the rows into a table. (I'm quite unsure of
# the syntax, so you'll have to adjust it as required.)
print table( Tr( \@tbl_rows ) );