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

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 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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-07-19 10:13 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (406 votes). Check out past polls.