I figured it out already! I ran a replace on the dst_port and replaced it with a whitespace which threw off the count. I've modified it to delete the whitespace and all works perfect.
Joshua Scott Security Systems Analyst, CISSP 626-568-7024 -----Original Message----- From: Scott, Joshua [mailto:Joshua.Scott@;Jacobs.com] Sent: Monday, November 04, 2002 5:42 PM To: '[EMAIL PROTECTED]' Subject: Help with Hash values and variable interpolation Hello all, I've got a file which contains ports and hostnames. I'd like to count the number of instances that each item occurs in my file. I'm having a difficult time with this. This is my script: Basically I'm splitting the first line a few times to get the data I need. What am I doing wrong? At the bottom you'll find a snippet of the file I'm parsing. Thank you for all your help! ############################################################### #/usr/bin/perl -w open (FILE,'c:\temp\outbound.traffic'); %allports=(); @file=<FILE>; foreach (@file) { chomp(); ($source,$other,$dest) = split(/\s/,$_); ($a,$b,$c,$d,$src_port)= split(/\./,$source); ($e,$f,$g,$h,$dst_port) = split(/\./,$dest); $sourceip = "$a.$b.$c.$d"; $destip = "$e.$f.$g.$h"; $dst_port =~ s/:/ /; push(@dstports,$dst_port); }; foreach $element (@dstports) { chomp($element); print "$element\n"; $allports{$element}++; } print "Port 53: $allports{53}\t Port 80: $allports{80}\n"; close (FILE); ###########################################################################3 FILE THAT IS BEING PARSED 112.58.26.32.32770 > 192.35.51.30.53: 64596[|domain] (DF) 112.58.26.32.32770 > 192.100.59.110.53: 24685 [1au][|domain] (DF) 112.58.26.4.2506 > 216.148.227.69.80: . ack 3280436924 win 2920 (DF) 112.58.26.4.2506 > 216.148.227.69.80: . ack 1759 win 1162 (DF) 112.58.26.4.2498 > 66.207.130.76.80: . ack 2195940947 win 7906 (DF) 112.58.26.4.2498 > 66.207.130.76.80: R 2576805184:2576805184(0) win 0 (DF) ============================================================================ ========== NOTICE - This communication may contain confidential and privileged information that is for the sole use of the intended recipient. Any viewing, copying or distribution of, or reliance on this message by unintended recipients is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. ============================================================================ == ============================================================================ ========== NOTICE - This communication may contain confidential and privileged information that is for the sole use of the intended recipient. Any viewing, copying or distribution of, or reliance on this message by unintended recipients is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. ============================================================================ == ====================================================================================== NOTICE - This communication may contain confidential and privileged information that is for the sole use of the intended recipient. Any viewing, copying or distribution of, or reliance on this message by unintended recipients is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. ============================================================================== -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]