#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Data::Dump; my @work_items; # Set up the parser my $twig = XML::Twig->new( twig_handlers => { usageAccum => \&gather_values, } } # Parse the file and gather work items $twig_parsefile('foo.xml'); # Process the work items for my $r (@work_items) { print Dumper($r), "\n"; } sub gather_values { # We just got a usageAccum node, so get the interesting attributes # and push them into the work item list. my $node = shift; push @work_items, { inclUnits => $node->{attr}->{inclUnits}; inclUnitsUsed => $node->{attr}->{inclUnitsUsed}; shared => $node->{attr}->{shared}; }; }