Hi Anthony.

Anthony Akens wrote:
> Just want to check and make sure this snippet of code will do what I think it will.
>
> Trying to copy all files from $reportsdir to $oldreportsdir

Well you shouldn't be asking us, as we can make guesses - usually
Very Good Guesses - as to whether it will work, but we are not your
computer and it may not agree with us.

  use strict;   # always
  use warnings; # usually

> my $reportsdir = '/usr2/reports';
> my $oldreportsdir = '/usr2/oldreports';
>
> # Move everything from the report directory to the old report directory
> opendir(DIR, $reportsdir) or die "can't opendir $reportsdir: $!";

- You're checking that the 'opendir' works on $reportsdir. How about checking
that $oldreportsdir exists?

  die "No destination directory" unless -d $oldreportsdir;

- You may prefer to

  chdir $reportsdir;

first, so that you don't have to assemble the fully-qualified source file name.

> while (defined($file = readdir(DIR))) {
>         move("$reportsdir/$file", "$oldreportsdir/$file")

- 'readdir' will give you directories as well as plain files. I suggest

  my @files = grep -f, readdir(DIR);
  foreach (@files) {
    :
  }

- What's this 'move' thing? Have you sneakily added 'use File::Copy without
telling us? If so, then

  move("$reportsdir/$file", $oldreportsdir);

is clearer.

- Do you want existing files of the same name overwritten? If not you need
to check first whether the destination file exists.

- Try your program first with 'copy' instead of 'move'. Then if it doesn't work
you shouldn't have done any damage.

>         or die "move failed: $!";
> }
>

Hmm. That's probably not the answer you were hoping for!

Even so HTH,

Rob




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

Reply via email to