in reply to I want to find a group of pattern in a xml file
use strict; use warnings; use XML::Twig; my $xfile = <<EOF; <people> <person><name>Jane Doe</name><age>42</age></person> <person><name>John Doe</name><age>43</age></person> <person><name>Foo Bar</name><age>43</age></person> </people> EOF my $t= new XML::Twig(); $t->parse($xfile); my $people = $t->root(); my @persons = $people->children('person'); for (@persons) { my $name = $_->first_child('name')->text(); my $age = $_->first_child('age' )->text(); if ($age == 43) { print "$name is $age\n" } } __END__ John Doe is 43 Foo Bar is 43
|
|---|