in reply to Read XML, Create Dir if not exist

I don't have time to post a code example now (hopefully soon), but i just wanted to pop in and say check out XML::XPath. I believe it would be an excellent fit for this problem.

24 hours later....

What a day! Ok, here is some code for you ...
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 }
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.

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:

my $callout_loc = '/path/to/xml/stuff'; my $file = "$callout_loc/mdlist.xml";
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:
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)