Hope this helps. I made a lot of changes, and I didn't comment them all. I'm not sure where/how you sent this to the list, but I'm responding back to the beginners list. Don't crosspost between lists if you can help it.
/\/\ark # warnings and strict help you to debug your code use warnings; use strict; # warnings requires you to declare your variables before you use them my $word; my $key; my $value; $inputFile="LogFile.dat"; # Opening LogFile.dat open (INPUT,$inputFile)||die("Can't open datafile: $!"); # you only want to read from <INPUT> once for each time through the loop. #You were reading lines that you never did anything with multiple times. while ($word = <INPUT>){ chomp $word; if ($word ne "<END>") { foreach $key (keys %seen){ if ($word eq $key) { $seen{$key}++ } } } } # I think you want to just print this once, so I moved it out of the while loop that reads the file while ( ($key, $value) = each %seen) { print "$key => $value\n"; } -----Original Message----- From: Allison Ogle [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 8:35 AM To: a a Subject: FW: Hash Values (again) 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 #$inputFile="LogFile.dat"; # Opening LogFile.dat #open (INPUT,$inputFile)||die("Can't open datafile: $!"); #while(<INPUT>){ # $word = <INPUT>; # chomp $word; # if ($word ne "<END>") { # foreach (keys %seen){ # if ($word eq $key) { # $seen{'$key'}++;} # } # $word=<INPUT>; # chomp $word; # } # while ( ($key, $value) = each %seen) { # print "$key => $value\n"; # } # } #} -----Original Message----- From: David Kirol [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 11:17 AM To: Allison Ogle Subject: RE: Hash Values (again) Not sure where you are with this 'problem' (code helps) $my_hash{'the_key'}++ -----Original Message----- From: Allison Ogle [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 9:59 AM To: [EMAIL PROTECTED] Subject: Hash Values (again) Hi, I have a hash with all the values set to zero. I want to use the filehandle and if the filehandle matches a key in the hash I want to increment the value from zero. Does anyone know how to do this? I'm lost with hashes :( Thanks, Allison -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]