OK, so thanks for the advice, all 3 of you. I tried out your suggestions, and got a temp script up and running. I threw in a bunch of print statements, to see what was happening, and it all looks good. But, something isn't working right. Somehow, the grep statement in the if isn't coming out right. I thought to use
if (-e $back)
instead of
if (grep {$back} @files),
but I am unsure how to test for files in a different directory..

#! /usr/bin/perl use strict; use warnings; use File::Path; use File::Copy; use Cwd; print "Your Input: "; chomp(my $filename = <STDIN>); my $dir = getcwd; my $backupdir = 'backup_files'; my $back = $filename . ".bak"; my $backful = $dir . "/" . $backupdir . "/" . $back; print "\$dir is: $dir\n"; print "\$filename is: $filename\n"; print "\$backupdir is: $backupdir\n"; print "\$back is: $back\n"; print "\$backful is: $backful\n"; unless (-e $backupdir) { mkpath($backupdir); } if (-e $backupdir) { if (-d $backupdir) { 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"; } } else { print "\$backupdir exists, but it is not a directory\n"; } }

Any thoughts on where I am going wrong?

Thanks


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.