in reply to Re^2: Is there a -e test for directories, like there is for files?
in thread Is there a -e test for directories, like there is for files?

-e $backful

Update: Specifically, replace

opendir (DIR, $backupdir) or die $!; my @files = readdir DIR; print "\@files is: \n"; foreach (@files) { print $_, "\n"; } if (grep {$back} @files) { print "Backup copy of $filename exists!\n"; } else { copy($filename, $backful); print "Backup copy of the file has been created\n"; }
with
if (-e $backful) { print "Backup copy of $filename exists!\n"; } else { copy($filename, $backful); print "Backup copy of the file has been created\n"; }

You should check whether the backup is the same, not whether it exists.
You should check whether the copy succeeded.
You should fix up your indenting.

Replies are listed 'Best First'.
Re^4: Is there a -e test for directories, like there is for files?
by mdunnbass (Monk) on Feb 08, 2007 at 21:15 UTC
    Wait - what's wrong with my indenting? I usually do:
    if (conditions) { do something } while (<>) { etc.. }

    The only thing I can see that's different is where I indent the closing brackets to. I usually put them even with the do something rather than even with the if (conditions). Is that wonky?

    Huh. Oh. I guess I could try to convert my habit.....

    But seriously, thanks for the help. I may have one or two additional things later on having tangentially to do with this, but for now, I'm great. Thanks.

    Matt

      FWIW, I was looking at this earlier post of yours a couple of days ago and, like ikegami, I didn't initially fathom the pattern of indenting you used. Once I understood your convention, the code was perfectly readable but, at first glance, the indenting style was not obvious and the code was as a consequence difficult to access.

      This is not meant as a criticism, just an observation following on from ikegami's post. Your indenting is perfectly logical and consistent but unusual. We all have our own coding styles and foibles and I'd hate to work somewhere where I was forced to conform to someone else's idea of good style.

      Cheers,

      JohnGG

      Sorry, I hadn't noticed the pattern when I made that comment. Forget I said anything.