Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

copy large number files in different dir's

by Anonymous Monk
on Jun 17, 2004 at 14:52 UTC ( #367645=perlquestion: print w/replies, xml ) Need Help??
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 ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://367645]
Approved by Happy-the-monk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-04-25 16:42 GMT
Find Nodes?
    Voting Booth?