On Thu, 2002-04-04 at 11:35, Allison Ogle wrote: > > Basically I have a hash with keys and all the values of these keys are set > to zero. Then I step through my input file with the filehandle and I want > to compare the filehandle to all of the keys in the hash. if there is a > match, I would like to increment the value. My hash is called %seen. Below > is what I have so far but it doesn't work. Do you have any ideas? Anything > would be greatly appreciated. Thanks, > Allison
Try this: #!/usr/bin/perl use strict; my $inputFile = 'LogFile.dat'; #set the name of the file my %seen; #create the seen hash #Opening LogFile.dat open INPUT, $inputFile or die "Can't open datafile: $!"; while(<INPUT>){ #read a line from $inputFile #trim off the $/ (which is currently "\n") chomp; #if the line matches "<END>" exit loop last if /<END>/; #use the line as a key into %seen and increment #the value associated with the key $seen{$_}++; } close INPUT; #loop through the hash printing out keys and values while (my ($key, $value) = each %seen) { print "$key => $value\n"; } #shorter version of above print "$_ => $seen{$_}\n" for keys %seen; -- Today is Prickle-Prickle the 21st day of Discord in the YOLD 3168 This statement is false. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]