in reply to Re: Attempting to fill a hash
in thread Attempting to fill a hash

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.

Replies are listed 'Best First'.
Re^3: Attempting to fill a hash
by pc88mxer (Vicar) on Jun 06, 2008 at 00:54 UTC
    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.
        they are also out of order
        As expected, according to the documentation (perldata):
        Note that just because a hash is initialized in that order doesn't mea +n that it comes out in that order. See sort for examples of how to ar +range for an output ordering.
Re^3: Attempting to fill a hash
by pc88mxer (Vicar) on Jun 06, 2008 at 01:36 UTC
    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.