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