Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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.


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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2018-05-26 02:41 GMT
    Find Nodes?
      Voting Booth?