http://qs321.pair.com?node_id=727156


in reply to Using associative arrays with I/O to interact with Prog. User

I created a cleaned up version of your code, but toolic beat me to it. His version is identical to what I cam up with, except mine lacked the  exists in the if, so I won't bother putting mine here

I found this article, The Perl Hash How-To, to be very valuble. I used to keep a copy pinned to the wall next to my desk because I was always getting screwed up by syntax.

As for your program, you had some misplaced commas and brackets instead of parenthesis where you created your hash. You had forward slashed where you needed backslashes for the newlines, and you had newlines in odd places (the newline escape sequence, '\n', needs to be in doublequotes to be interpreted as you expect).

Also, you need to chomp your input, otherwise you end up with a trailing newline character that will cause a mis-match, even if you enter what you think should be a match.

I'm not too familiar with Ruby - is the style of comparison you use how you determine if a value is in a hash in that language? I've not looked at too much Ruby code but I seem to recall seeing something similar. Here a node about comparing hash values, and an article at Perl.com with some good has info.

It looks like Perl syntax is your stumbling block, as well as perhaps habits learned from another language. It shouldn't take much more than a bit of practice, and maybe reading over someone else's code or some Perl documentation to get past that :)