I was wondering if it were possible to extract the hashes from the XML:: Simple output without knowing the elements' name beforehand? I've searched the web and only found tutorials how to get elements from a certain file with certain tags.

use XML::Simple;
use XML::Parser;
use Data::Dumper;
my $file1 = $ARGV[1];
my $data = $xml->XMLin($file1);
print Dumper($data);

and the output:

$VAR1 = {
          'book' => [
                      'title' => 'Book 1 title',
                      'author' => [
                                  'Author 1',
                                  'Author 2'
                      'title' => 'Book 2 title',
                      'author' => [
                                  'Author 3',
                                  'Author 4'

I'd like to be able to parse any XML file with different tags. Or is there a better way to do it?

7 Years
Discussion Span
Last Post by vitana

this module provides simple xml functionality only. in your case I prefer to create recursive function to discover hashes in the $data because it takes few lines

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.