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

Re^5: Get data from an XML file heading

by haukex (Archbishop)
on Feb 20, 2020 at 17:47 UTC ( [id://11113266]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Get data from an XML file heading
in thread Get data from an XML file heading

It looks like it's taking the first element of the array called 'nodes' and converting it into a hash called attrs. Is that correct? my %attrs = %{ $nodes[0] };

Almost right, it's not exactly converting, it's doing a hash dereference, see perlreftut and perlref. Basically:

my %hash = ( foo => "bar" ); my $hashref = \%hash; # take a reference to the hash print $hashref->{foo},"\n"; # acccess a value via the ref my %attrs = %{ $hashref }; # makes a shallow copy

(In this case, there's a slightly more complicated thing going on in the background, that you don't necessarily need to care about. $nodes[0] is an object, which provides a special behavior when you use it like a hash reference: it returns the attributes of the element as a hash. That's why I can use this object as if it were a hash reference and dereference it, even though it's a much more complex object than just the attributes in a hash - I can call methods on it, etc. It's documented in XML::LibXML::Element under "Overloading".)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found