First off, you don't say that you want data in HTML, but your code seems to be trying that. I'll go with the assumption that you do not want you data in HTML, and it's relatively easy to convert the result to HTML if that's what you want.
The code you posted suffers from the problem that you're generating output with each line, where what you really want is a summary. This means that you should just accumulate your results until you've read the entire file, and then form your output.
Here's a minimal reworking of your code:
my $test = "Joe's Store"; my $log_file = "c:\log.txt"; open(LOGFILE, "< $log_file") or die("Could not open log file."); my %seen = (); my %typeseen = (); # read it in while(<LOGFILE>) { # we might be better with a split() here next unless /(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*? +)$/; my ($item, $logintype) = ($1, $4); $seen{$item}++; $typeseen{$item}{$logintype}++; } # dump it out foreach my $item (sort keys %seen) { print "$item:\n"; print "\tLog in activity: ", $seen{$item}, "\n"; foreach my $type (sort keys %{$typeseen{$item}}) { print "\t", $type, " activity: ", $typeseen{$item}{$type}, "\n"; } }
Incidentally, if this is a standalone script, you might want to consider setting $test from the command line.
In reply to Re: Uniqueness in Text Data File Help
by fizbin
in thread Uniqueness in Text Data File Help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |