in reply to Print specific attributes "not their values" of an XML file using Perl
use warnings; use strict; use XML::Twig; my $str = ' <Foo> <Validation byCluster="true" byOtherPop="false" byHapMap="true" by +1000G="true"/> </Foo> '; my $t = XML::Twig->new( twig_handlers => { Validation => \&valid }, ); $t->parse($str); sub valid { my ($t, $tag) = @_; my %atts = %{ $tag->atts() }; for my $att (keys %atts) { print "$att\n" if $atts{$att} eq 'true'; } } __END__ by1000G byCluster byHapMap
UPDATE: runrig /msg'd me that only 'true' should be chosen.
|
|---|