GertMT has asked for the wisdom of the Perl Monks concerning the following question:

hello Monks,

While trying to use File::Copy I encounter a problem. The script below should copy a set of files (html, png, css, javascriptje) to a folder with the name "to_move". This is the folder that's mirrored with a folder on a server. On one of my computers (Mac iBook) the script given below runs ok. Setting up the script with exactly the same setup on a different machine (old Mac Powerbook) it runs only if I type in my terminal

./move.pl.

If I try to run it within a series of scripts like
system("perl move.pl");
it doesn't run. All my files remain in the original folder and there's no message/warning or anything. Maybe someone out there can tell me what I'm doing wrong?

Thanks,
Gert
#!/usr/bin/perl -w #script_name = move.pl use strict; use diagnostics; use File::Copy; my $file_html = undef; my $file_png = undef; my $file_css = undef; my $javascriptje=undef; my @files_html = <*.html>; foreach $file_html (@files_html) { move( "$file_html", "./to_move/$file_html" ) or die "Copy html fai +led: $!"; } my @files_css = <*.css>; foreach $file_css (@files_css) { copy( "$file_css", "./to_move/$file_css" ) or die "Copy css failed +: $!"; } my @javascriptjes = <*.js>; foreach $javascriptje (@javascriptjes) { copy( "$javascriptje", "./to_move/$javascriptje" ) or die "Copy ja +vascr failed: $!"; } my @files_png = <*.png>; foreach $file_png (@files_png) { move( "$file_png", "./to_move/$file_png" ) or die "Copy png failed +: $!"; }

Replies are listed 'Best First'.
Re: file::copy problem
by runrig (Abbot) on Aug 17, 2007 at 22:10 UTC
    Are you sure the wrapping script does not chdir? Did you try a standalone script with just the system(...) command? Put the following in your move.pl script to make sure you're in the right directory:
    use Cwd qw(cwd); print cwd(),"\n";
      thanks for your feedback. I didn't know about

      Cwd

      Found out though that I or it was in the correct directory. I had the idea I'd done something elementary wrong in my code. I'll let my output go into my to_move direct as a solution.
      thanks again.
      Gert
        Also, as another sanity check, print the loop variables within each of your loops to make sure the loops are at least trying to process a list of files.