in reply to Evolution of a Perl Programmer (new backup script)

I'll avoid repeating what's already been said. As a point of note though:
foreach my $file (@$exc) { if($_ eq $file) { $skip =1; } }

is broken, since it'll keep looping through checking for exclusions even if it's already found that this file or directory is in fact excluded from being backed up. Realistically, in a small, simple backup script like this, run on your own computer most of the time, it probably wouldn't matter. But it IS generally a good idea to leave a loop when you no longer need it to execute. :)

foreach my $file (@$exc) { if($_ eq $file) { $skip =1; } last if $skip; }

Replies are listed 'Best First'.
Re: Re: Evolution of a Perl Programmer (new backup script)
by extremely (Priest) on Dec 21, 2000 at 16:48 UTC
    Don't test an exit flag, just set the flag and exit.
    foreach my $file (@$exc) { $skip=1, last if ($_ eq $file); }

    --
    $you = new YOU;
    honk() if $you->love(perl)

      Ah, but the only reason for the flag is to immediately skip to the next iteration of the while loop, which can be done without a flag at all:
      FILE: while (defined(local $_ = readdir(LS))) { foreach my $file (@$exc) { next FILE if ($_ eq $file); } my $file = $dir . $_; my $append = "tar -rf $tarfile $file 2>> $ERRORFILE"; system($append); print "\t$file\n"; }
      Although I would use a hash for the excludes, instead of looping over an array for each file in the directory, especially since the most common case of a file not being in the exclude list would also be the slowest case.

      I also recommend testing the readdir() assignment with defined, as I did above, so that the while loop will not stop prematurely if there's a file named '0'.

      Thank you!!!