Joshua Scott wrote: > > Hello all, Hello,
> 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'); You should _always_ verify that the file opened successfully. Also, you can use slashes instead of backslashes in file names. open FILE, 'c:/temp/outbound.traffic' or die "Cannot open 'c:/temp/outbound.traffic': $!"; > %allports=(); > > @file=<FILE>; > > foreach (@file) { You shouldn't read the whole file into an array unless you _really_ need to. while ( <FILE> ) { > chomp(); You don't really need to chomp as you are not using the data at the end of the line. > ($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"; next unless my ( $source, $src_port, $dest, $dst_port ) = /^([\d.]+)\.(\d+)[ >]+([\d.]+)\.(\d+)/; > $dst_port =~ s/:/ /; > > push(@dstports,$dst_port); print "$dst_port\n"; $allports{$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) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]