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

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)

Replies are listed 'Best First'.
Re: Re: Re: Evolution of a Perl Programmer (new backup script)
by chipmunk (Parson) on Dec 23, 2000 at 08:40 UTC
    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'.

Re: Re: Re: Evolution of a Perl Programmer (new backup script)
by Anonymous Monk on Dec 23, 2000 at 07:38 UTC
    Thank you!!!