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

Let's suppose we have a $source glob string like:

and a $destination like

I want to copy all the files from $source to $destination in a platform-independent way

At the moment the best I can think of is:

system("cp $source $destination");

Is there a better way?

-Andrew.

Replies are listed 'Best First'.
Re: Platform-independent copying multiple files
by Skeeve (Parson) on Oct 18, 2005 at 09:47 UTC
    perldoc File::Copy

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Platform-independent copying multiple files
by Delusional (Beadle) on Oct 18, 2005 at 10:57 UTC
    cp isn't platform-independent. I beleive copy is aliased on linux systems these days, but don't rely on that.

    Your probibily better off going with Skeeve's recomendation to use File::Copy. But then again, you could go hard core, and manually open the files and bitstream binary copy through Perl, but is that really necessary (let alone safe)?
Re: Platform-independent copying multiple files
by ambrus (Abbot) on Oct 18, 2005 at 13:36 UTC

    File::Copy is a core module to copy files.

    You can use globs or the File::Glob module to find files matching the glob.

      I've used:
      my @all_matches = glob "*.txt"; my @files = grep {-f} @all_matches;
      for the glob part... :)