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


In reply to Re: Using associative arrays with I/O to interact with Prog. User by eighty-one
in thread Using associative arrays with I/O to interact with Prog. User by dlapre01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.