in reply to How would you handle arrays of arrays?

Given your data sample, how about this?
#!/opt/local/bin/perl use strict; use warnings; use File::Path; use File::Copy; my $source = '/tmp'; my $destination = '.'; my @cfgA = qw( configapp1/conf/dactest1 configapp1/conf/4k_logging.properties configapp1/conf/logging.properties ); my @cfgB = qw( configbbb/b1.0 configbbb/b1.0.config ); foreach (@cfgA, @cfgB) { my ($path, $file) = m|(.*)/(.*)|; &File::Path::mkpath($path,0,0755) unless -d $path; if (-f "$source/$file") { copy("$source/$file", "$destination/$path/"); } elsif (open(IN,">$destination/$path/$file")) { close(IN); } else { warn("Couldn't copy or create $destination/$path/$file!"); } }
Update:Added $destination to the copy, open, and warn statements.

Replies are listed 'Best First'.
Re^2: How would you handle arrays of arrays?
by gokuraku (Monk) on Jan 09, 2009 at 16:41 UTC
    Very nice, but all in all I have 16 arrays now, might make the foreach loop long and hard to read.

    I do like the data entries in the arrays though, I hadn't really used File module like that, but having each one as a single directory path would make it easier to read.
      As for the foreach getting too long, the following layout might be useful:
      foreach ( @cfgA, @cfgB, #@cfgC, # not this time! @cfgD, @cfgE, #@cfgF, # not! @cfgG, # etc ) { }
      But it might be easier to maintain the paths and files on your filesystem than in your script. I.e., create all the paths and files in your $local_dir; and just copy the desired paths; or perhaps tar up each configuration and untar the desired ones.