in reply to How to copy a file

Perl can handle multiple filehandles at once...
open OLD "<", $oldfile or die "Can't open $oldfile ($!)\n"; open NEW ">", $newfile or die "Can't open $newfile ($!)\n"; print NEW while(<OLD>); close OLD; close NEW;
err... didn't actually test that... but I'm sure it works :)

Replies are listed 'Best First'.
Re^2: How to copy a file
by runrig (Abbot) on Feb 28, 2008 at 22:38 UTC
    File::Copy will at least copy more than a line at a time...by default 2Mb at a time for files, 1k for non-files. Which is likely preferable to one line at a time. But I think I'd go with system("cp ...")
Re^2: How to copy a file
by ack (Deacon) on Feb 28, 2008 at 21:43 UTC

    I have used this approach numerous times (though after I discovered File::Copy I've used it much more). The only thing I missed (typical of my not seeing all the power one can get into a single line) is the 'print NEW while(<OLD>)' single line.

    I am curious that in the original Anonymous Monk's code the input from OLD is to a scalar, doesn't that just read in a single record from the OLD document?

    ack Albuquerque, NM