You should use strict; That would show you some problems. > #$inputFile="LogFile.dat"; > > # Opening LogFile.dat > #open (INPUT,$inputFile)||die("Can't open datafile: $!"); > > #while(<INPUT>){ This is not necessary...and in fact you skip every other line. The above while loop reads from INPUT and puts the current line in $_. If you want it in word, then say while( $word = <INPUT> ) { > # $word = <INPUT>; > # chomp $word; > # if ($word ne "<END>") { A foreach loop places it's variable in $_ as well. You are using $key which is undefined. You really don't even need a foreach loop here How about just $seen{$key}++ if exists( $seen{$key} );
That only increments the value if the value exists. Also notice that you said $seen{'$key'}. This will not interpolate $key, instead, you would be indexing $seen by the literal $key, not the value of $key. > # foreach (keys %seen){ > # if ($word eq $key) { > # $seen{'$key'}++;} > # } Once again, this is not necessary, as the while loop takes care of it > # $word=<INPUT>; > # chomp $word; > # } This is fine. > # while ( ($key, $value) = each %seen) { > # print "$key => $value\n"; > # } > # } > #} Tanton > -----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]