XML::Simple folds (by default) on the name= attribute. At lines -3, -8 from the end you have two <members> lines with the same name="AttributeDesc". This fooled XML::Simple into treating the two blocks as the same, allowing the second instance to overwrite the first. By adding KeyAttr=>[] as an option to XMLin, this default behaviour is suppressed and the expected result is obtained.
use feature ":5.14";
use warnings FATAL => qw(all);
use strict;
use Data::Dump qw(dump pp);
use XML::Simple;
my $x = XMLin(<<'END', KeyAttr=>[]);
<classes name="Panoply::AttributeDesc">
<all_members name="AttributeDesc" protection="public" scope="Panop
+ly::AttributeDesc" virtualness="non_virtual"/>
<all_members name="AttributeDesc" protection="public" scope="Panop
+ly::AttributeDesc" virtualness="non_virtual"/>
<all_members name="description" protection="public" scope="Panoply
+::AttributeDesc" virtualness="non_virtual"/>
<all_members name="name" protection="public" scope="Panoply::Attri
+buteDesc" virtualness="non_virtual"/>
<all_members name="value" protection="private" scope="Panoply::Att
+ributeDesc" virtualness="non_virtual"/>
<public_members>
<members kind="variable" name="name" protection="public" static=
+"no" type="std::string" virtualness="non_virtual"></members>
<members kind="variable" name="value" protection="public" static
+="no" type="std::string" virtualness="non_virtual"></members>
<members kind="variable" name="description" protection="public"
+static="no" type="std::string" virtualness="non_virtual"></members>
</public_members>
<public_methods>
<members const="no" kind="function" name="AttributeDesc" protect
+ion="public" static="no" virtualness="non_virtual" volatile="no">
<parameters declaration_name="name" type="const std::string &a
+mp;"/>
<parameters declaration_name="value" type="const std::string &
+amp;"/>
<parameters declaration_name="desc" default_value="""
+;" type="const std::string &"/>
</members>
<members const="no" kind="function" name="AttributeDesc" protect
+ion="public" static="no" virtualness="non_virtual" volatile="no"></me
+mbers>
</public_methods>
</classes>
END
#pp($x);
sub r($$$;$);
sub r($$$;$)
{my ($r, $l, $e, $a) = @_;
$a = [] unless $a;
return unless $l and ref($l);
if (ref($l) =~ /HASH/)
{for(sort keys %$l)
{unless (/$e/)
{push @$a, $_;
r($r, $l->{$_}, $e, $a);
pop @$a;
}
else
{&$r(@$a);
}
}
}
elsif (ref($l) =~ /ARRAY/)
{for(1..@$l)
{unless ($l->[$_-1] =~ /$e/)
{push @$a, $_;
r($r, $l->[$_-1], $e, $a);
pop @$a;
}
else
{&$r(@$a);
}
}
}
}
r sub {say "@_"}, $x, "parameters";
Produces
public_methods members 1
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.