Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-19 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found