# for the students of 1st month. sam1 sam2 # for the students of 2nd month. mike1 mike2 #for the students of 3rd week. luke1 luke2 # for the students of 3nd month. ben1 ben2 #### use XML::Twig; #purpose: get the string of the related $class+$month+index sub parse_a_counter { my ($twig, $class) = @_; my $class_name = $class->{'att'}->{'name'}; my @report = $class->children('report [@type="month"]'); for my $report (@report){ my @string_list = $report->children_text('string'); } $class->flush; # free the memory of $counter } my $roots = { 'class[@name="english"]' => 1 }; my $handlers = { class => \&parse_a_counter }; my $twig = new XML::Twig(TwigRoots => $roots, TwigHandlers => $handlers); $twig->parsefile('class_report.xml');