http://www.perlmonks.org?node_id=273204


in reply to retrieving attribute text with xml::twig

The attributes are accessed using $_->atts , the values would then be values %{$_->atts}.

Just for the fun here is a compact way to do this:

#!/usr/bin/perl -w use strict; use XML::Twig; XML::Twig->new( start_tag_handlers => { _all_ => sub { print join( ' - ' => values %{$_->a +tts}), "\n"; } } ) ->parse( \*DATA); __DATA__ <doc> <elt att="first attribute">text</elt> <elt att="second attribute" att2="foo">text</elt> <elt att="bar">text</elt> </doc>