Use Perl to read an XML configuration file
Suppose you have a file (settings.xml) like this :
Code:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="settings.xsl" ?>
<settings>
<setting>
<title>Use XML with Perl</title>
<color>#8800aa</color>
<size>12</size>
<height>90</height>
<width>468</width>
</setting>
</settings>
With Perl, you can read the contents of the XML file and use the values.
Code:
use XML::Simple;
use Data::Dumper;
# Create XML object
$xml = new XML::Simple;
# Load the xml data in $books
my $settings = $xml->XMLin("settings.xml");
# Print XML data
print uc("title: ") . "$settings->{setting}->{title} \n";
print uc("color: ") . "$settings->{setting}->{color} \n";
print uc("size: ") . "$settings->{setting}->{size} \n";
print uc("height: ") . "$settings->{setting}->{height} \n";
print uc("width: ") . "$settings->{setting}->{width} \n";
Result:
mdmsoft@linux-4nve:~/perl> perl xml.pl
TITLE: Use XML with Perl
COLOR: #8800aa
SIZE: 12
HEIGHT: 90
WIDTH: 468