in reply to Re: XML::Simple Multi Level Array
in thread XML::Simple Multi Level Array

How do I loop through the hash in the {Batch} index? You'll notice I have a zero.

Replies are listed 'Best First'.
Re^3: XML::Simple Multi Level Array
by ikegami (Patriarch) on Feb 11, 2010 at 16:57 UTC
    # This looks wrong, but it's what you gave us my $batches = $data->{Jobs}{Job}{Blocks}{Block}{Batches}{Batch}; for my $batch (@$batches) { # This looks also wrong my $item = $batch->{Items}{Item}; print $item->{CorporateName} . "\n"; print $item->{Amount} . "\n"; }
    I would have expected something more like
    my $jobs =$data->{Jobs}{Job}; for my $job (@$jobs) { my $blocks = $job->{Blocks}{Block}; for my $block (@$blocks) { my $batches = $job->{Batches}{Batch}; for my $batch (@$batches) { my $items = $batch->{Items}{Item}; for my $item (@$items) { print $item->{CorporateName} . "\n"; print $item->{Amount} . "\n"; } } } }

    By the way , the following would simplify your tree:

    GroupTags => { Jobs => 'Job', Blocks => 'Block', Batches => 'Batch', },