Quantcast
Channel: dereferencing a XML::Simple hash - Stack Overflow
Viewing all articles
Browse latest Browse all 3

dereferencing a XML::Simple hash

$
0
0

I have an XML file that looks like this

<booklist><book type="technical"><author>Book 1 author 1</author><author>Book 1 author 2</author><title>Book 1 title</title><isbn>Book1ISBN</isbn></book><book type="fiction"><author>Book 2 author 1</author><author>Book 2 author 2</author><title>Book 2 title</title><isbn>Book2ISBN</isbn></book><book type="technical"><author>Book 3 author 1</author><author>Book 3 author 2</author><author>Book 3 author 3</author><title>Book 3 title</title><isbn>Book3ISBN</isbn></book></booklist>

When i put the file through a dumper - it looks like this:

#!/usr/bin/perluse strict ;use warnings ;use XML::Simple ;use Data::Dumper ;my $book = ();my $booklist = XMLin('book.xml_with_attrib');print Dumper($booklist);#foreach $book (@{$booklist->{author}} ) {#     print $book->{title}  ;#     print "\n";#}

This is the Dump:

/tmp/walt $ /tmp/walt/bookparse_by_attrib.pl$VAR1 = {'book' => [                    {'isbn' => 'Book1ISBN','title' => 'Book 1 title','author' => ['Book 1 author 1','Book 1 author 2'                                ],'type' => 'technical'                    },                    {'isbn' => 'Book2ISBN','title' => 'Book 2 title','author' => ['Book 2 author 1','Book 2 author 2'                                ],'type' => 'fiction'                    },                    {'isbn' => 'Book3ISBN','title' => 'Book 3 title','author' => ['Book 3 author 1','Book 3 author 2','Book 3 author 3'                                ],'type' => 'technical'                     }                   ]        };

However when I try and print out the authors - this is what I get.

foreach $book (@{$booklist->{book}} ) {     print $book->{author}  ;     print "\n";}ARRAY(0x249a140)ARRAY(0x249a098)ARRAY(0x2499fc0)

How would I print out author?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>