in reply to Attempting to fill a hash

You want to change:
while (<$wordhandle>) { $deadstring = chomp; $hashlist{$deadstring} => 1; $wordcount++; }
to:
while (<$wordhandle>) { chomp; $hashlist{$_} = 1; $wordcount++; }
You had two small errors...

1. chomp returns the number of characters chomped, so $deadstring = chomp assigns a number to $deadstring.

2. You're using the fat comma => instead of the assignment operator = in $hashlist{$deadstring} => 1;.

Replies are listed 'Best First'.
Re^2: Attempting to fill a hash
by TwistedTransistor (Novice) on Jun 06, 2008 at 00:43 UTC
    First off, thank you pc88. That does finally get the hash to fill out where it admits not empty, but for some reason I can't pull up any values. The very first line in the text file is 'a' and the line print "$hashlist{a}\n"; which should display 1, simply prints a newline character as if it couldn't find the key named a EDIT* - i assigned the %hashlist to an @array, and when I print the first couple $array it displays completely unexpected values, is there a limit to the size of a default hash that I could be overflowing it (109,000) entries in the text file p.s. that makes perfect sense about the way i had chomp assigned, that's what I get for using VB for so long.
      I would add:
      use Data::Dumper; print Dumper(\%hashlist);
      to see what %hashlist contains. That will probably clarify a lot of things.
        Added that plug in and ran the code. (I used a majorly slimmed down version of the text file for this example.) Here are the results This is what is in the text file in order:
        a aah aahed aahing aahs aardvark aardvarks aardwolf ab This is what Dump returned $VAR1 = { ' => 1, 'a ' => 1, 'aahed ' => 1, 'aahs ' => 1, 'aardwolf ' => 1, 'aahing ' => 1, 'aardvark ' => 1, 'aardvarks ' => 1, 'ab ' => 1 'aah };
        I notice both the vales and the keys are there, however when i do. print "$hashlist{a}\n"; it returns null followed by a \n. they are also out of order, but for the use I have in mind that is unimportant as long as they all read.
      Based on your Data::Dumper output it is clear that you still have newlines at the end of your hash keys. Are you sure you are doing:
      chomp; $hashlist{$_} = 1;
      or do you have something else?
        you still have newlines

        rather looks like carriage returns (\r) to me.

        I wonder if s/\s+$// or similar would have not ended the misery sooner than continued use of chomp (in retrospect, of course).
        Yes, I do. Just an FYI, when I create a blank file from scratch and type in some random words like a b c d e f
        it dumps the correct data, and I can pull up values so I'm begining to think the file i'm using may not be interpreted correctly in perl.