in reply to language selection via libxml
If you add use diagnostics; it will print a more verbose error message explaining this scenario (there is no variabele @ID which you keyboarded into your string)
string quoting/interpolation are explained in perlintro and Strings in Perl: quoted, interpolated and escaped
You can simplify your xpaths, like this (untested , may contain typos)
sub enumerate_languages { my( $xmltree ) = @_; my @nodes = $xmltree->findnodes( '/language' ); my @langs = map { $_->tagName } @nodes; return @langs; } sub get_language { my( $xmltree, $lang ) = @_; my @nodes = $xmltree->findnodes( "/language/$lang/*" ); my %pairs ; for my $node ( @nodes ){ $pairs{ $node->getAttribute('ID') } = $node->textContent; } return %pairs; }
FWIW, traditionally this is done using .po/.mo files, each language gets its own file ... gettext.. and all that ... :)
|
|---|