Loading ...
Sorry, an error occurred while loading the content.

Hashing/ Wrong output!!!!

Expand Messages
  • portia317@yahoo.com
    I need help with hashes- I have this piece of code: my %sourceip; my %countsip; my %countlogs; my %count_logs; my %count_ip; my %loger; my %logsrc; foreach
    Message 1 of 1 , Jun 1, 2001
    • 0 Attachment
      I need help with hashes- I have this piece of code:

      my %sourceip; my %countsip;
      my %countlogs; my %count_logs;
      my %count_ip; my %loger;
      my %logsrc;

      foreach (@data) {
      my ($log_source,$time_stamp,$source_ip)=split(/,/);


      $sourceip{$source_ip}=$source_ip;
      $countsip{$source_ip}++;
      $count_ip{$source_ip}= ($countsip{$source_ip});

      $logsrc{$log_source}=$log_source;
      $loger{$source_ip}=$log_source;


      my @sorted_highest_to_lowest= sort {$count_ip{$b} <=> $count_ip{$a}
      } keys %count_ip;


      foreach (@sorted_highest_to_lowest) {
      print "SOURCE IP = $sourceip{$_} total hits are $count_ip{$_} \n";
      print "LOG SOURCE = $loger{$_} \n";
      }

      My output looks like this:

      SOURCE IP = 192.101 total hits are 2
      LOG SOURCE = Meade
      SOURCE IP = 192.100 total hits are 1
      LOG SOURCE = Monmouth
      SOURCE IP = 192.102 total hits are 1
      LOG SOURCE = Yuma
      SOURCE IP = 192.103 total hits are 1
      LOG SOURCE = Monmouth

      My data file looks like this:

      Monmouth,2000-05-20 00:00:09-04,192.100
      Jackson,2000-04-21 00:00:10-05,192.101
      Meade, 2001-01-05 00:00:11-04,192.101
      Yuma, 200-03-11 00:00:12-05,192.102
      Monmouth,200-04-10 00:00:10-08,192.103

      I need to print out multiple log source's for a source_ip. I think it
      has to do with the relationship of the source ip to log source. There
      is one source ip but many log sources. Then i need to count how many
      times each log source was hit by that source ip.

      Any help would would very much appreciated- i've been struggling with
      this for 2 days!
      Thanks,
      Portia
    Your message has been successfully submitted and would be delivered to recipients shortly.