Saw something similar to this topic on the Monastery Gates but thought I'd ask all the same, because I'm not really getting anywhere.

I want to do the following from a text file with entries delimited by :'s
1. read a line from a text file
2. first word(s) becomes the hash name
3. next 4 words go into key,value pairs
4. repeat to EOF

ex:
name: bob: jane: joe: sue:
name2: john: me: oh: my:

So, I want a hash called name. With key,value pairs to look something like first,bob....second,jane and so on. And a second hash called name2. With key,value pairs to be first, john....second,me...etc.

I've been playing with regexes and splits with varying degrees of a total lack of success.

John


In reply to parsing text file into a hash? by ralfthewise

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.