http://www.perlmonks.org?node_id=594758

bitman has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: TreePP (Hash or Array)
by davorg (Chancellor) on Jan 15, 2007 at 15:36 UTC

    You write as though you assume that everyone should just know what "TreePP" is. I think you probably mean XML::TreePP.

    If that's the case then perhaps the force_array option will be useful.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: TreePP (Hash or Array)
by eff_i_g (Curate) on Jan 15, 2007 at 15:34 UTC
    Are you talking about XML::TreePP? You can use ref to check the return type: if it's an array, OK; if it's a hash, put it into an array; continue processing.

    You may want to contact the author to see if this could be handled better in the module, or perhaps there is reason behind the behavior.


    Update: Kudos to davorg for reading the docs :)
      Except, it didn't work. But I used your solution, but I guess my code isn't that elegant though.
      if ( ref $tree->{$xfile}->{$rec} eq 'HASH' ) { my $x=$tree->{$xfile}->{$rec}; delete $tree->{$xfile}->{$rec}; $tree->{$xfile}->{$rec}[0]=($x); }
        force_array did not work? Is it not what it seems to be, a bug, or, upon second glance, a (gasp!) user error?