Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Evolution of a Perl Programmer (new backup script)

by mothra (Hermit)
on Dec 21, 2000 at 08:45 UTC ( [id://47725]=note: print w/replies, xml ) Need Help??


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!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://47725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found