in reply to Moving files

This is a result of your using $_ as a global variable. I cant see any good reason that you shouldn't pass the name of the file to be moved into your moving() function.

I use the most powerful debugger available: print!

Replies are listed 'Best First'.
Re^2: Moving files
by Nkuvu (Priest) on Jul 28, 2005 at 21:38 UTC
    Or just remove the sub entirely and move the code into the loop.

      This is what i had at the beginning, at first it worked
      because i was just moveing the files to another
      folder on the c:, but when i start moveing
      the files to a mapped drive all this started up so I tried
      to rewrite it.
      print "Enter the month and day (ex:0605)\n"; $date = <stdin>; chomp($date); move(c:/atmcaf00,K:/atm/atmcaf00$date); move(c:/atmcaf00,K:/atm/atmcaf01$date); move(c:/atmcaf00,K:/atm/atmcaf12$date); move(c:/atmcaf00,K:/atm/atmcmf01$date); move(c:/atmcaf00,K:/atm/atmcmf12$date); print "All the ATM files have been renamed and move to the ATM folder\ +n"; $wait = <stdin>;
        What I'm referring to is changing this code (extra blank lines removed for space considerations):
        sub moving { print "Moving $_ to the K:/ATM \n"; move("$old$_","$new$_$date"); print "$_ has been moved to the K:/ATM\n"; print "---------------------------------------------\n"; } foreach (@files) { &moving; }
        into something more like:
        foreach (@files) { print "Moving $_ to the K:/ATM \n"; move("$old$_","$new$_$date"); print "$_ has been moved to the K:/ATM\n"; print "---------------------------------------------\n"; }
        Personally I'd also use a named variable instead of $_, though, so I'd write something more like:
        foreach my $file (@files) { print "Moving $file to the K:/ATM \n"; move("$old$file","$new$file$date"); print "$file has been moved to the K:/ATM\n"; print "---------------------------------------------\n"; }
        But changing $_ to a named variable is not a functional change -- just makes the use of the loop variable a bit more clear.
      I tried that and it still did the same thing
      (copied the first file and skipped over the rest)
        I've copied the program, created test files & directories, and moved files successfully under a Unix system using this program.

        I would suggest stepping through the program with a debugger or adding a print join " ", @files; print "\n"; at the end of your loop to find if your @files array is getting munged somehow. That is where my first guess at the problem would be.

        My second guess would involve permission issues and or failure of the move as suggested by others.

        And my final guess would involve issues with your installation of perl under windows...

        My working test code


        -Scott