Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, This script works fine for cp file from one path to another. However, need to perfrom this on 50ish dir, is it possible to use an array containing the path locations to cp from and to?
my $folder = '/path//'; find (\&copy, $folder); sub copy { system "cp x /newpath/'; system "cp y /newpath/'; }

Replies are listed 'Best First'.
Re: copy large number files in different dir's
by tinita (Parson) on Jun 17, 2004 at 15:13 UTC
    i don't understand your code example, but i'm guessing:
    use File::Copy; my @paths = ( [qw(/dir1/file /dir2)], [qw(/dir3/file /dir4)], ... ); for (@paths) { my ($from,$to) = @$_; copy($from,$to) or die $!; }
    is that what you want?
      yes, that would work, but it would mean having to change the $from for eac directory. Could i have list of directories and pipe that list into the script?
        The only thing you would need to change is the @paths = () list of directories in the script, not the loop which grabs $from, $to pairs from that list. You could acquire the @paths list from anywhere that provides a list: slurp a file, read from STDIN, etc.

        --
        [ e d @ h a l l e y . c c ]