#!/bin/perl -w ############################################################# # # # This example lists all XML modules in freshmeat.xml # # # # It uses TwigRoots for maximum speed and minimal memory # # usage: the twig is only built within the elements # # designated in TwigRoots. # # # ############################################################# use strict; use XML::Twig; my $twig= new XML::Twig( # create the twig TwigRoots => { name => \&name, # build the twig only for name elements } , # and call the name handler for each ); if( my $file= $ARGV[0]) { $twig->parsefile( $file); } # process the twig else { $twig->parse( \*STDIN); } sub name { my( $twig, $name)= @_; my $name_text= $name->text; # get the name if ($name_text=~ /\AXML::/) { print "$name_text\n"; } $twig->purge; # free memory }