Bootstrap FreeKB - Perl (Scripting) - Data::Dumper and XML::Simple
Perl (Scripting) - Data::Dumper and XML::Simple

Updated:   |  Perl (Scripting) articles

When using XML::Simple to parse an XML file, Data::Dumper is an essential module so that you can understand how XML::Simple is interpreting the XML. Take for example the following XML.

  <name id="1">Bugs Bunny</character>



Here is an example of how to use Data::Dumper.

use strict;
use warnings;
use XML::Simple;
use Data::Dumper;

my $xml= XMLin("example.xml");
print Dumper $xml;


Which will produce the following.

  • "name" is the root key
  • "content" and "id" are child keys below the root key
  • "Bugs Bunny" is a value of the "content" key
  • "1" is a value of the "id" key 
  • Data inside of { } is interepreted as a hash
$VAR1 = {
          'name' => {
                     'content' => 'Bugs Bunny',
                     'id' => '1'


Dumper shows that the path to Bugs Bunny is name -> content -> Bugs Bunny, thus the following markup would be used to print "Bugs Bunny". 

print $xml->{'name'}->{'content'};


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter 8785e0 in the box below so that we can be sure you are a human.