Have some problem with Perl hashes.
I have an XML:
<?xml version="1.0" encoding="utf-8"?>
<SvnRequestUsers>
<AccessCode>$TR0ngP@ssvv0rd!</AccessCode>
<SvnUsers>
<SvnUser>
<Username>svn.testname</Username>
<Password>jA=B*+q%</Password>
<Create>true</Create>
</SvnUser>
<SvnUser>
<Username>svn.testname2</Username>
<Password>jA=B*+q%</Password>
<Create>true</Create>
</SvnUser>
</SvnUsers>
</SvnRequestUsers>
I want to loop through SvnUser nodes. When I use
my $usersList = $ref->{‘SvnUsers’};
foreach my $key ( @{$usersList->{'SvnUser'}} )
{ ..... }
That works when there is more than one node but doesn’t work for One node.
When use
my @usersList = $ref->{‘SvnUsers’}->{‘SvnUser’};
foreach my $key ( @usersList )
{ ..... }
that works only when exactly one node is there.
Where is the trick ???
If you are using XML::Simple, you probably want to turn on ForceArray, either globally (which will probably require you to add more array dereferences in your code) or for the specific element that may have one or many nodes; see https://metacpan.org/module/XML::Simple#ForceArray-names-in—important.