- . , : , tag => sub { handler( @_, $my_arg) } $my_arg, . .
. Getopt::Long qq{} , XPath, .
use strict;
use warnings;
use XML::Twig;
use Getopt::Long;
my $counter_name= 'music';
my $type= 'month';
my $id= 4;
GetOptions ( "name=s" => \$counter_name,
"type=s" => \$type,
"id=i" => \$id,
) or die;
my @results;
my $twig= XML::Twig->new(
twig_roots => { qq{counter[\@name="$counter_name"]}
=> sub { parse_a_counter( @_, $type, $id, \@results); } } )
->parsefile('counter_test.xml');
print join( "\n", @results), "\n";
sub parse_a_counter {
my ($twig, $counter, $type, $id, $results) = @_;
my @report = $counter->children( qq{report[\@type="$type"]});
for my $report (@report){
my @stringSet = $report->children( qq{stringSet[\@index="$id"]});
for my $stringSet (@stringSet){
my @string_list = $stringSet->children_text('string');
push @$results, @string_list;
}
}
$counter->purge;
}