Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

This may fall in the dangerous category of "why using variables to name variables is stupid" (yes, I've read the thing).

Then again, it may not. I'm going to be very explicit about the objective of all this so I don't get someone shoving a sword through my belly immediately, but what I really need to know is not how-to-do-all-the-things but just how to do this:

I need to dynamically create a nest of hashes from a text file with data separated by tabs and newlines.

example:

Assault Assault Battery Assault and Battery Sexual Sexual Assault Deadly Assault with a deadly weapon with Assault with a deadly weapon without Assault without a deadly weapon Aggravated Aggravated Assault

I want to pull such a text file (of depth unknown) into a (potentially indefinite) nest of hashes that can be used to derive outputs from the data without including the outputs explicitly in the code.

The size of the file, and depth of the contextual relationships contained within, will vary. The number of tabs before a word or phrase will dictate its depth in the hash, and a new hash tree will be created by any word or phrase with no tabs preceding. Any $value followed by a newline and more tabs than preceded it should become a hash itself, where any $value followed by a newline and the same number or fewer tabs as preceded it should become a scalar (will be treated as output values)

It is important that people (not necessarily me) be able to modify the desired outputs ("Assault and Battery", "Assault with a deadly weapon" etc - i.e.) in the text file, rather than in the code.

Is this something that is possible in Perl?

Thank you for indulging my nubcakery


In reply to dynamic hash nesting by karrakis

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (13)
    As of 2014-09-23 22:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (241 votes), past polls