in reply to dir handle

Recently, I've been trying to use Path::Tiny to solve similar problems, as it has everything you need in one place.
#!/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
    can you do it without oop!
      Sure I can, but why?
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        because Path::Tiny doesn't work on my system i tried it with FIle::Copy