perlquestion
perlvroom
Ok, the following script does what i need, but i was hoping someone could school me on how to do this more effeciently:
<code>
use XML::Twig;
my $t= XML::Twig->new( twig_handlers =>
{ 'settings' => \&file,
}
) ->parsefile( 'sample.xml');
sub file{
my($t, $settings)=@_;
foreach($settings->att('key')){
if($settings->att('key') eq 'a'){
$a = $settings->att('value');
}
if($settings->att('key') eq 'b'){
$b = $settings->att('value');
}
}
}
</code>
XML snippet:<br>
<settings key="a" value="1"/><br>
<settings key="b" value="2"/>
<br>
The goal is to declare the "key" attribute as a variable with it's value equal to the "value" attribute in the same element, for all "settings" elements.