http://qs321.pair.com?node_id=582660


in reply to Re^3: cp in perl
in thread cp in perl

Funny, my copy of File::Copy's documentation plainly states:

The "copy" function takes two parameters: a file to copy from and a file to copy to.

It then quite clearly goes on to note the optional third parameter which is in no manner, shape, or form a path name of any kind. The post I was responding to seemed to imply that they expected copy to work like cp with multiple arguments and a trailing directory name, which it doesn't (as the documentation explains; "I copy from the first argument to the second argument").

I'm sorry that there exist people dense enough to blindly presume things without reading the documentation, but it's quite obvious what copy allows for arguments.

Replies are listed 'Best First'.
Re^5: cp in perl
by Hofmator (Curate) on Nov 08, 2006 at 07:27 UTC
    Well, sadly (or happily) the copy function also works with a directory as the 2nd parameter, copying the 1st parameter into the directory given by the 2nd - and not just file to file. Furthermore, the module gives the possibilty to export functions named 'cp' and 'mv', just like corresponding *nix functions.

    These factors make it (sadly!) more probable that copy is assumed to do something it does NOT do, i.e. copy @files, $dir.

    Btw, move has the same problems, simply moving its 1st onto its 2nd parameter, silently ignoring any other arguments.

    -- Hofmator

    Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^5: cp in perl
by Anonymous Monk on Nov 07, 2006 at 16:37 UTC
    All I'm saying that regardless what the documentation says, is that if people suggest that 'File::Copy::copy' is Perl's answer to 'cp', then people *will* treat it as 'cp'. It works well if you give it two arguments. It will erase your file if you give it three.

    IMO, that's very, very bad. It violates the principle of least surprise in one of the worst ways possible.