Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: How to get content of an XML::easytree output

by Tworec (Initiate)
on Mar 08, 2013 at 08:52 UTC ( #1022355=note: print w/replies, xml ) Need Help??


in reply to Re: How to get content of an XML::easytree output
in thread How to get content of an XML::easytree output

First of all, thanks for your reply. I changed all variables $element to $node and errors I reported are gone. But unfortunately a new one came. Not a HASH reference at line: if ($node->{type} eq 'e'). I think it's because of the $tree variable is ARRAY, but there is the main problem. My brain cannot really understand how to go threw an array of hashes and print it's elements. Should I write something like
if(ref($node) eq HASH) do the code I have elsif(ref($node) eq ARRAY) $node = shift;
?

Replies are listed 'Best First'.
Re^3: How to get content of an XML::easytree output
by kcott (Chancellor) on Mar 08, 2013 at 09:07 UTC

    Something like the following (untested) skeleton code:

    sub print_easy_tree { my $node_array_ref = shift; for my $node (@$node_array_ref) { if ($node->{type} eq 'e') { ... } elsif ($node->{type} eq 't') { ... } else { ... } } }

    -- Ken

      Great, it works now! Only if I could ask one more question.. Why @$ in @$node_array_ref? Why not just @?

      And if you know about a site where could I learn more of perl accessing to data, could you please give me a link? Of course I used google and found several sites with perl tutorials even in my language, but I mean if you know any you could personally recommend.

        In essence, $node_array_ref is a reference to an array; it is a single scalar value. @$node_array_ref (which you might see written as @{ $node_array_ref }) dereferences $node_array_ref to produce an array of scalar values. See perlreftut for a short tutorial about references.

        The main Perl link that I have bookmarked is http://perldoc.perl.org/perl.html. This has links to all the Perl documentation. I'd recommend you start with perlintro, then look at the links under Tutorials and then move on to the Reference Manual. There is a vast amount of information here: don't try to learn everything at once; instead, get a feel for which sections contain which information and revisit often - you'll build up a solid body of core knowledge with the ability to quickly find specifics when you need to.

        -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022355]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-04-19 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?