Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to access multiple values from XML file in our perl file

by choroba (Cardinal)
on Jan 09, 2015 at 12:35 UTC ( [id://1112734]=note: print w/replies, xml ) Need Help??


in reply to How to access multiple values from XML file in our perl file

Dereference uses curly brackets:
foreach (@{ $Enbfield->{field} }) { # ^ ^
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: How to access multiple values from XML file in our perl file
by vasuperl (Acolyte) on Jan 09, 2015 at 13:53 UTC

    Even i tried that one by changing that braces. But it is also showing error as "syntax error at field.pl line 15, near ") {" syntax error at field.pl line 18, near "}" Execution of field.pl aborted due to compilation errors."

      Semicolon missing here perhaps ?
      print "@field \n"; # ^
      Consider using XML::Twig
      #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $xml = 'value.xml'; my $twig = new XML::Twig( twig_handlers =>{ field => \&field } ); $twig->parsefile($xml); sub field { my ($t,$e) = @_; for ($e->children){ if ($_->gi eq 'key'){ print $_->att('name')." "; } elsif ($_->gi eq 'value'){ print $_->att('id')."\n"; } } }
      poj
        This, considering the following from XML::Simple's documentation (emphasis mine):

        STATUS OF THIS MODULE ^

        The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.

        The major problems with this module are the large number of options and the arbitrary ways in which these options interact - often with unexpected results.

        Patches with bug fixes and documentation fixes are welcome, but new features are unlikely to be added.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112734]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-19 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found