Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

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
    [usemodperl]: question
    [usemodperl]: perldoc -v 'ARGV' works but perldoc -v "STDIN' does not, but they are both filehandles. is there a perldoc for STDIN?
    [usemodperl]: (typo not withstanding :)
    usemodperl thinks about loose coupling...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (5)
    As of 2018-06-19 19:19 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (114 votes). Check out past polls.