#!/bin/perl -w use strict; use XML::Twig; my $twig= XML::Twig->new(pretty_print=>'indented'); $twig->parse(\*DATA); my $root=$twig->root; $twig->root->first_child->sort_children( sub { $_->{'att'}->{"type"}}); $twig->root->first_child->first_child->sort_children( sub { $_->text}); #$twig->root->sort_children_on_att("type"); #$twig->root->sort_children_on_field('mainterm'); $twig->print; __DATA__ plague disease pestilence panadol zorro xenon aspirin #### ---------- perl compile ---------- aspirin panadol xenon zorro plague disease pestilence Output completed (3 sec consumed) - Normal Termination