in reply to Unique items in a text file

Use a hash, something like the following code

my %erg = (); while(<DATA>) { my @row = split(/,/,$_); ++$erg{$row[3]}; } print $_ . ': ' . $erg{$_} . '<br />' . "\n" foreach (keys %erg); __DATA__ Auto,00883,pw00,DX,4/15/2004,10:12:59,1110046,1 Auto,00883,pw00,FA,4/15/2004,10:15:45,, Magic,006513,pw13,Login,4/15/2004,10:16:23,, Car Wash,006513,pw3h,Not Found,4/15/2004,10:16:57,1232246, Home and Auto,006513,pw6513,DI,4/15/2004,10:17:09,15134346,1 Auto,00883,pw00,FA,4/15/2004,10:17:17,, Home,006513,pw6513,Login,4/15/2004,10:17:38,, Home,006513,pw6513,DI,4/15/2004,10:17:44,151234326,1 Deal Time,006513,pw001,Login,4/15/2004,10:53:31,1, Car Wash,006513,pw3h,DI,4/15/2004,10:53:46,11238748,1 Magic,006513,pw13,Login,4/15/2004,11:01:25,0,
Edit: fixed missing right-curly.
Edit II: fixed spelling error, removed untested-remark.

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus

Replies are listed 'Best First'.
Re: Re: Unique items in a text file
by Anonymous Monk on Apr 20, 2004 at 14:34 UTC
    Hi,
    I run the code and it is printing back the total for all the item just like the problem I was having before, but thanks for your effort.
    Result prints:
     48

      Dunno, that's what I get:

      DI: 3<br /> Not Found: 1<br /> FA: 2<br /> Login: 4<br /> DX: 1<br />

      regards,
      tomte


      An intellectual is someone whose mind watches itself.
      -- Albert Camus

        How would I do this based on the datgiven?
        I got the same here, how would you do if you had to add this numbers up instead of displaying them in order?
      I got the same here, how would you do if you had to add this numbers up instead of displaying them in order?