in reply to Can't access data stored in Hash - help!

corcra:

A couple notes:

While I'm advocating that you add a few print statements during development, you don't need to leave them in when your code works. So don't be afraid to put in a few prints here and there. (I tend to use a prefix on the print strings to help me figure out what's printing and why. Something like:

while (my $line = <DATA>) { chomp $line; print "$.: $line\n"; ### my ($x, $y, $key, $bar) = split /,/, $line; print "A: x=$x, y=$y, k=$key, b=$bar.\n"; ### if ($key =~ /[^\d]/) { print "BOOM: non-numeric key value <$key>\n"; ### ... stuff ... } else { print "B: plover=...\n"; ### ... other stuff ... } }

Putting the prefixes on your lines lets you use grep (or equivalent) to dig through your output to find lines of interest. For example, I may run my program and check for non-numeric keys like this:

perl foobar.pl >tmp grep -E '^BOOM:' tmp | wc -l

When I'm happy with a section of code, I tend to comment out the print statements, and when it all works as I like it, I go back and delete them (the lines marked ###).

Finally, notice that after every variable in a print statement, I have a graphic character (., >, etc.) so I can see if the string has trailing blanks, carriage returns, etc.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Can't access data stored in Hash - help!
by corcra (Initiate) on Aug 05, 2014 at 08:51 UTC

    roboticus, thank you for your suggestions! I will keep these in mind from now on.