Rule #1: Please state how it's not working.

Rule #2: Please show us sample input data.

Lot's of little problems, but let's focus on the important stuff first.

my($src, $dst, $rule1) = (split /,/)[1];
(split /,/)[1] returns the element with index 1 (2nd element) in the list that split returns. If you really want $src to be the 1st element (index 0), use (split /,/)[0]. (See split for other options.)

Since you don't need the other vars, that reduces to

my $src = (split /,/)[0];
---
$hash{$src} = $src;
The hash value can contain anything, it doesn't need to be the hash key. I would rewrite this as
$hash{$src}++; # count occurrences
---
next if $src =~ /$hash{$src}/;
This is useless, as it's the last statement in the loop, and $hash{$src} has just been set to $src on the line before.

There's no reason to step through the file twice, as you already have all of the info stored. Instead of all the rest, do this

foreach (keys %hash) { print "$_ was seen $hash{$_} times\n"; }
Cheers,

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: Counting the Number of Times and IP Appears by QM
in thread Counting the Number of Times and IP Appears by Dru

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.