in reply to dir handle
#!/usr/bin/perl use warnings; use strict; use Path::Tiny; setup(); # This is the solution: for my $file (path('test1')->children) { $file->copy('test2') unless path('test2/' . $file->basename)->exis +ts; } sub setup { my %structure = ( test1 => [qw( abc.txt xyz.txt )], test2 => [qw( abc.txt sdf.txt fgh.txt )], ); my $i = 0; for my $dir (keys %structure) { for my $file (@{ $structure{$dir} }) { path("$dir/$file")->touchpath->spew($i++); } } }
Update: you might need to run the loop twice (with a small modification) to copy files from test2 to test1 if it's desired as well.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: dir handle
by Mjpaddy (Acolyte) on May 27, 2014 at 10:17 UTC | |
by choroba (Cardinal) on May 27, 2014 at 10:18 UTC | |
by Mjpaddy (Acolyte) on May 27, 2014 at 10:34 UTC | |
by ww (Archbishop) on May 27, 2014 at 11:44 UTC | |
by Mjpaddy (Acolyte) on May 27, 2014 at 11:58 UTC | |
|