Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using associative arrays with I/O to interact with Prog. User

by eighty-one (Curate)
on Dec 01, 2008 at 17:11 UTC ( [id://727156]=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://727156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found