in reply to Read XML, Create Dir if not exist

You first read the whole XML file, then extract the 'name' attribute of the 'md' elements and then process them. This is perfectly valid, but given that you are interested only in a small part of the information, it is probably simpler to read the md elements and process the information (i. e. create the directories) as you go. XML::Twig is perfect for this kind of task:

#!/usr/bin/perl -w use strict; use XML::Twig; my $callout_loc = "."; my $file = "./mdlist.xml"; #create the parser (twig) #and tell it what sub to call if it finds an 'md' element my $twig = new XML::Twig (twig_handlers => {md => \&process_md}); #parse the file #process_md will be called every time an 'md' element is found $twig->parsefile ($file); #that's it exit 0; sub process_md { my ($t, $md) = @_; #get the name attribute my $name = $md->att ('name'); #create the dir unless it already exists my $dirname = "$callout_loc/$name"; unless (-d $dirname) { print "Creating $dirname...\n"; mkdir $dirname or die "Could not create dir $dirname: $!\n"; } else { print "$dirname already exists!\n"; } }
Much shorter, isn't it? And btw, I tested it, it works. HTH,

pike