Dear Monks,

What am I doing wrong here?

My problem:
I keep getting "cannot create regular file ..." errors.

Here's the code:
#!/usr/bin/perl -w use strict; use Getopt::Std; use vars qw/$opt_c $opt_f $opt_t $opt_h/; my $unDos = 0; my $top = 'E:\MY_DIR'; getopts( 'hcf:t:' ); if( $opt_f ) { $unDos = $opt_f; } if( $opt_f ) { $top = $opt_t; } if( $opt_h ) { &usage(); exit; } my @fileNames = ( 'Bob', 'Mary', 'Jane'); my $lt = localtime(); $lt =~ s/ /_/g; if( defined( $opt_c ) ) { print "Strip out :'s\n"; $lt =~ s/:/_/g; } foreach my $fn (@fileNames) { my $file = $top . "/" . $fn; my $src = &UnDosify ( "$file.dat", $unDos ); my $tgt = &UnDosify ( "$file.dat-$lt", $unDos ); if( -T "$src" ) { `mv $src $tgt`; } else { print "$src does not exist and that's ok.\n"; } } sub UnDosify { my ($fileName, $doit) = @_; if( $doit == 1 ) { $_ = $fileName; s/E:/\/cygdrive\/e/g; s/\\/\//g; $fileName = $_; } else { $_ = $fileName; s/\/cygdrive\/e/E:/g; s/\//\\\\/g; $fileName = $_; } print "Undosify is returning $fileName\n"; return $fileName; } sub usage { print <<USAGE; $0 [-h][-c][-f <UnDos> ][-t <Top Dir>] UnDos can be 0 or 1 USAGE }
Here's what happens when I run it:
bash-2.05a$ ls -l /cygdrive/e/MY_DIR total 0 -rw-r--r-- 1 rbc None 0 Mar 5 13:47 Bob.dat -rw-r--r-- 1 rbc None 0 Mar 5 13:47 Jane.dat -rw-r--r-- 1 rbc None 0 Mar 5 13:47 Mary.dat bash-2.05a$ ./colon_bug.pl -f 1 -t /cygdrive/e/MY_DIR Undosify is returning /cygdrive/e/MY_DIR/Bob.dat Undosify is returning /cygdrive/e/MY_DIR/Bob.dat-Tue_Mar__5_14:09:13_2 +002 mv: cannot create regular file `/cygdrive/e/MY_DIR/Bob.dat-Tue_Mar__5_ +14:09:13_2002': No such file or directory Undosify is returning /cygdrive/e/MY_DIR/Mary.dat Undosify is returning /cygdrive/e/MY_DIR/Mary.dat-Tue_Mar__5_14:09:13_ +2002 mv: cannot create regular file `/cygdrive/e/MY_DIR/Mary.dat-Tue_Mar__5 +_14:09:13_2002': No such file or directory Undosify is returning /cygdrive/e/MY_DIR/Jane.dat Undosify is returning /cygdrive/e/MY_DIR/Jane.dat-Tue_Mar__5_14:09:13_ +2002 mv: cannot create regular file `/cygdrive/e/MY_DIR/Jane.dat-Tue_Mar__5 +_14:09:13_2002': No such file or directory
... but ...
bash-2.05a$ ./colon_bug.pl -c -f 1 -t /cygdrive/e/MY_DIR Strip out :'s Undosify is returning /cygdrive/e/MY_DIR/Bob.dat Undosify is returning /cygdrive/e/MY_DIR/Bob.dat-Tue_Mar__5_14_10_14_2 +002 Undosify is returning /cygdrive/e/MY_DIR/Mary.dat Undosify is returning /cygdrive/e/MY_DIR/Mary.dat-Tue_Mar__5_14_10_14_ +2002 Undosify is returning /cygdrive/e/MY_DIR/Jane.dat Undosify is returning /cygdrive/e/MY_DIR/Jane.dat-Tue_Mar__5_14_10_14_ +2002 bash-2.05a$ ls -l /cygdrive/e/MY_DIR total 0 -rw-r--r-- 1 rbc None 0 Mar 5 13:47 Bob.dat-Tue_Mar__5_ +14_10_14_2002 -rw-r--r-- 1 rbc None 0 Mar 5 13:47 Jane.dat-Tue_Mar__5 +_14_10_14_2002 -rw-r--r-- 1 rbc None 0 Mar 5 13:47 Mary.dat-Tue_Mar__5 +_14_10_14_2002

... works?

Why?

In reply to Another File::Copy problem by rbc

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.