Date: Thu, 9 Aug 2001 05:16:38 -0700 (PDT) 
From: perl newbie <[EMAIL PROTECTED]> | Block
Address | Add to Address Book 
Subject: Re: recursive file copy 
To: [EMAIL PROTECTED] 
         
 


Hello,

I am using the following code to do two things:

1) create a unique directory name using @ARGV, and
2) recursively copy the contents of a source directory
into the target directories.

However, when I attempt to do this, I am getting the
following errors about infinite loops.

% perl copy.pl t1 t2
cp: {WORK_AREA} is a descendant of $HOME/samples.
Copying results in infinite loop(not copied)
cp: {WORK_AREA} is a descendant of $HOME/samples.
Copying results in infinite loop(not copied)


I would appreciate help with the following questions:

1) what am I possibly doing wrong ?
2) Is there a problem with my usage of the foreach
loop in this case.
3) Is there a better way to accomplish what I am doing
?


Thanks 

PN


PS:  Here is the source code:

--------- Perl Source Code ------------

#!/usr/bin/perl -w
use strict;
use POSIX;

##########################
###    MAIN PROGRAM    ###
##########################


# set environment variables.

$ENV{WORK_AREA} = "/tmp/regr_tests";

# forward declarations, required due to the use
# of the "strict" pragma.

# variable declarations
my $dir_name;
my $cal_date = POSIX::strftime("%m%d%Y",localtime());
my $proc_id = getpid();

# function declarations
sub myMkDir;


# loop through the command line arguments and
# check for the existence of the named directories.
# Create new directories ONLY if they are not already
# existing.

   foreach $dir_name (@ARGV){

# create unique directory names per each run.
   $dir_name= "$dir_name" . "_". "$cal_date" . "_" .
"$proc_id" ;

        myMkDir "$ENV{WORK_AREA}/$dir_name";

# recursively copy files from DB area to TEST area.
system("/usr/bin/cp -rf \$HOME/samples
\$ENV{WORK_AREA}/\$dir_name");
}

### end of main

##########################
####  Sub myMkDir     ####
##########################

sub myMkDir {
  my $dir = shift;

  if (-e $dir) {
    if (!(-d $dir)) {
      # Exist, but not a directory, it's a file
      die "Error: can't create directory $dir, a file
of that name already exist
s\n"; }
     else { die "Error: can't create directory $dir, a
directory of that name al
ready exists\n"; }
  } else {
    mkdir $dir, 0755;
  }
}



__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to