#!/bin/perl -w ############################################################# # # # This example just prints a list of names and module # # description from the freshmeat.xml file # # # # It builds the whole tree in memory # # # ############################################################# use strict; use XML::Twig; my $twig= new XML::Twig(); # create the twig if( my $file= $ARGV[0]) { $twig->parsefile( $file); } # build it else { $twig->parse( \*STDIN); } my $module_list= $twig->root; # grab the root my @modules= $module_list->children; # get its children foreach my $module ( @modules) { my $e_name = $module->first_child( 'name'); # get the elements my $e_description = $module->first_child( 'description'); my $name = $e_name->text; # get their text my $description = $e_description->text; print "$name: \t$description\n"; # print the info }