Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

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

It's very likely that i'm misunderstanding this, but let's see. It sounds like you want to deanonymise a hash of hashes, ie to create a named hash with the exact same data structure? i'm not sure why you would need to do that, but i've been fiddling with some examples and i can't see any reason for not just using:

my %bar = %$foo;

On the other hand, the cookbook says that you should use dclone for this sort of thing, which is in a CPAN module called Storable. I think the difference is that dclone will create a whole new structure whereas the assignment above just creates an identity between your named hash and the anonymous one, so they still use the same references. There might be reasons why that's undesirable, but i'm definitely out of my depth there. Perhaps when you want to amend values in the named hash but not affect the original?

But you also say that you want to parse the data, by which i suppose you mean that you want each key/value pair to pass through your hands so that you can decide whether or not it's important. That seems like a separate problem to me, and the key is probably a test for hashness: the rest is pretty simple and the way to go about it depends on your data. If you know that it's only there are no arrays in the HoH, then you might be able to get away with using ref($foo{$_}), which will return 'HASH' if $foo{$_} is a hash and FALSE if it isn't a reference at all. I also remember seeing something that just used a regex to check whether the string 'HASH' was in the value, but that sounds highly dubious to me. Anyway, given such a test, it would be relatively simple to step through every pair and look for whatever you're looking for.

But if you're really thinking of stepping through the HoH and testing for particular name-value pairs, or something like that, then I'd say you should be looking for a different approach rather than dealing with this problem as it stands: there's no point parsing xml line by line, which is essentially what you'd be doing. At the very least, you should be able to simplify your code by knowing whether the important data corresponds to the first H of HoH or the second (or third or whatever). Otherwise you lose all the advantages of using xml in the first place. Also i've tried to make up a few ways of doing that - much more fun that what i'm supposed to be doing - and none of them have worked :(

Hope this helps.


In reply to Re: How do I parse values of a complex anonymous hash of hashes? by Anonymous Monk
in thread How do I parse values of a complex anonymous hash of hashes? by Anonymous Monk

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 making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2014-07-26 17:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (178 votes), past polls