On 6/13/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hi
I'm struggling with the use of XML::Simple so was hoping that someone
might be able to help me. I'm kind of new to perl, especially when
dealing with hash references. I would like to iterate through the hash
that is created by the XMLIn function. Here is my code:
snip
    $FirstReject = $ref->{RejectRecord}->[0]->{Reason};
    print "First Reject is $FirstReject \n";
snip

So, $ref is a reference to a hash of arrays of hashes.  You have three
things that can be iterated over.  You can iterate over all three like
this:

for my $k (sort keys %$ref) {
       for my $i (0 .. $#{$ref->{$k}}) {
               for my $k2 (sort keys %{$ref->{$k}[$i]}) {
                       print "$k:$i:$k2 is $ref->{$k}[$i]{$k2}\n";
               }
       }
}

However, I bet you want to iterator over all of the contents of the
RejectRecord key like this

my $max = @{$ref->{RejectRecord}};
for my $i (1 .. $max) {
   print "record $i of $max failed because
$ref->{RejectRecord}[$i-1]{Reason}\n";
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to