Greetings all,
A bit off topic but here is a little script I use to investigate how XML::Simple is parsing my *.xml files
This is meant to be run from the same directory that contains the xml files. Nothing novel but I find it useful.
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
#get all the .xml files from this base directory
unless(opendir(CNF, '.')){
die "Unable to open directory for reading\n";
}
my @config_files = sort grep { /\.xml$/ && -f "$_"} readdir(CNF);
#clean up
close CNF;
DISPLAY:
{
print "Please select a file for parsing:\n";
for(my $i = 1; $i-1 < scalar(@config_files); $i++){
print "\t$i. $config_files[$i-1]\n";
}
print "\n\t# ";
}
my ($filenum, $filename);
chomp($filenum = <STDIN>);
if($filenum !~ /^\d$/){
print "Please select the number\n";
goto DISPLAY;
}else{
$filename = $config_files[$filenum-1];
}
unless(open(CNF, $filename)){
die "unable to open XML config file". $!;
}else{
my $file = do {local $/ = undef; <CNF>};
close CNF;
my $xs = new XML::Simple();
my $ref = $xs->XMLin($file);
print "\nXML structure (current).\n";
print Dumper($ref);
print "\n";
ENDING:{
print "\n Q to quit\n";
my $key;
chomp($key = <STDIN>);
unless($key =~ /q/i){
goto ENDING;
}else{
exit;
}
}
}
-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|