in reply to Read XML, Create Dir if not exist
24 hours later....
What a day! Ok, here is some code for you ...And that's it - much 'simpler' than XML::Simple if you ask me. Encapsulating code into subroutines is usually the way to go, but sometimes it's overkill, especially with small Perl scripts like this one.use strict; use warnings; use XML::XPath; my $xp = XML::XPath->new(filename => 'mdlist.xml'); my @mds = map { $_->getAttribute('name') } $xp->findnodes('/md_map/md[@name]'); for my $dir (@mds) { # create $dir if applicable }
One thing to note -- you are relying upon your script being executed from a particular directory in order for it to work. Not good. Instead, use absolute paths to the files:
And so forth. Another point is that you might be doing too much error checking. I would try to create the directory even if it exists and pass that error message to the user instead:my $callout_loc = '/path/to/xml/stuff'; my $file = "$callout_loc/mdlist.xml";
mkdir $dir or warn "$dir already exists: $!";
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|