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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.