in reply to XML & data structure parsing fun (XML::Simple ??)

It's better to give XML::Simple a few hints so that it creates a datastructure that's consistent and fine to work with.

use strict; use warnings; use XML::Simple; my $xml_raw = <<XML_RAW; <survey> ... </survey> XML_RAW my $data = XMLin($xml_raw, ForceArray => [qw(river fish)], KeyAttr => +[]); foreach my $Animal (@{$data->{animals}{fish}}) { print <<"*END*"; [ Survey information for: $Animal->{name} ]: Saltwater:$Animal->{saltwater} Freshwater:$Animal->{freshwater} Rivers covered in survey: *END* for (@{$Animal->{river}}) { print $_, "\n"; } print "\n"; }
or you could use XML::Rules and print the report as the file is being parsed:
use strict; use warnings; use XML::Rules; my $xml_raw = <<XML_RAW; <survey> ... </survey> XML_RAW my $parser = XML::Rules->new( stripspaces => 7, rules => { _default => '', river => 'content array', fish => sub { print <<"*END*"; [ Survey information for: $_[1]->{name} ]: Saltwater:$_[1]->{saltwater} Freshwater:$_[1]->{freshwater} Rivers covered in survey: *END* for (@{$_[1]->{river}}) { print $_, "\n"; } print "\n"; }, } ); $parser->parse($xml_raw);
or
my $parser = XML::Rules->new( stripspaces => 7, rules => { _default => '', river => sub {'.river' => "$_[1]->{_content}\n"}, fish => sub { print <<"*END*"; [ Survey information for: $_[1]->{name} ]: Saltwater:$_[1]->{saltwater} Freshwater:$_[1]->{freshwater} Rivers covered in survey: $_[1]->{river} *END* }, } ); $parser->parse($xml_raw);