in reply to Re: Copy file from Windows server to antoher windows server
in thread Copy file from Windows server to antoher windows server

Thanks, What the difference between File::Copy and using system copy command? Does the File::Copy use less server processing?
  • Comment on Re^2: Copy file from Windows server to antoher windows server

Replies are listed 'Best First'.
Re^3: Copy file from Windows server to antoher windows server
by ikegami (Patriarch) on May 03, 2006 at 23:00 UTC
    • File::Copy's copy puts a lot effort in being portable.
    • It's well tested.
    • It doesn't launch a seperate process, so it's faster and uses less memory. Instead, it uses a system call (or Perl code if the OS doesn't have such a call).
    • It can copy from/to file handles instead of just from/to files.
    • Its arguments are not subject to shell interpretation. (The way in which you used system is buggy and unsafe.)
    • It's makes checking for success much easier.
    • It provides meaningful error messages in $!, on most systems.

    On the other hand,

    • Your expression is not portable.
    • It's not well tested. In fact, there are bugs.
    • It launchs *two* seperate processes, so it's slower and uses more memory.
    • It can't copy from/to file handles, just from/to files.
    • Its arguments are subject to shell interpretation (although that can be fixed). The way in which you used system is buggy and unsafe. (Bug 1)
    • It thinks it succeeds even if the copy fails, as long as the shell was successfully loaded. (I think.) (Bug 2)
    • $! does not contain what you think it does here. It definitely does not contain why the copy failed when it does. (Bug 3)
Re^3: Copy file from Windows server to antoher windows server
by nimdokk (Vicar) on May 03, 2006 at 18:50 UTC
    For one thing, you don't have to spawn (I think that's the right term) a second process if you use Perl's copy instead of the system command. Also, I find it easier to verify that your copy in fact worked correctly (though this can be done with a system call as well I'm sure).