File::Copy.. general questions

R

rohan

Hello,
I need to copy a bunch of files.. I am doing something like
--------------------------
use File::Copy;

our @sl=
("file1","fileG2","fileS3","fileD4","etc");

foreach $f1(@sl){
copy($f1,"bak_".$f1) or do { print "Error copying file $f1";
next; }
}
--------------------------------

my question.. is there a more simpler/faster way for doing the above..
i do not want to do it in a command line... has to be part of a
script.. and dont want to use any non standard modules
also are there any pitfalls with the above method? lol i seem to have a
lot of questions.. your answers will be appriciated..

...R
 
T

Tintin

rohan said:
Hello,
I need to copy a bunch of files.. I am doing something like
--------------------------
use File::Copy;

our @sl=
("file1","fileG2","fileS3","fileD4","etc");

foreach $f1(@sl){
copy($f1,"bak_".$f1) or do { print "Error copying file $f1";
next; }
}
--------------------------------

my question.. is there a more simpler/faster way for doing the above..
i do not want to do it in a command line... has to be part of a
script.. and dont want to use any non standard modules
also are there any pitfalls with the above method? lol i seem to have a
lot of questions.. your answers will be appriciated..

I'd write it as

#!/usr/bin/perl
use strict;
use warnings;

my @sl = qw(file1 fileG2 fileS3 fileD4 etc);

foreach my $file (@sl) {
copy $file, "bak_$file" or warn "Error copying file $file $!\n";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,953
Members
47,507
Latest member
codeguru31

Latest Threads

Top