#! perl use strict; use warnings; use XML::Twig; #------------------------------------------------------------------------------ package Shape; use Moo; use namespace::clean; has type => ( is => 'ro' ); has class => ( is => 'ro' ); has coords => ( is => 'ro' ); sub print { my $self = shift; printf qq[<%s class = "%s" coordinates = "%s">\n], $self->type, $self->class, $self->coords; } #------------------------------------------------------------------------------ package main; my $twig = XML::Twig->new; $twig->parse( do { local $/; } ); my @shapes; for my $class ($twig->root->children('class')) { my $class_name = $class->att('id'); push @shapes, Shape->new(type => $_->gi, class => $class_name, coords => $_->att('coordinates')) for $class->children; } $_->print() for @shapes; __DATA__ #### 23:58 >perl 967_SoPW.pl 23:58 >