use strict; use warnings; use XML::Twig; use vars qw/ %options /; use Getopt::Std; use Switch; #---- #Code to treat the file #---- my $t = XML::Twig->new( twig_handlers => { object => \&animal_handler } ); $t->parsefile($File); sub animal_handler { my ($t, $obj) = @_; if ($obj->att('type') eq 'dog') { my $name; my $id; my $bname; for my $prop ($obj->children('property')) { $name = $prop->att('value') if $prop->att('name') eq 'name'; $id = $prop->att('value') if $prop->att('name') eq 'dog_breed_id'; $gname = $prop->att('value') if $prop->att('name') eq 'dog_breed_name'; } print "$id,$name,$bname\n"; } }