in reply to What is the easiest way to copy one file to another?

Or, if you have RAM to spare or aren't working with large files, you could
open (FH, "file.txt") or die "$!"; undef $/; $slurped_file = <FH>; # whole file resides in $slurped file now. open (CFH, ">copied_file.txt") or die "$!"; print CFH $slurped_file; # file.txt contents now reside in copied_file.txt. # close your filehandles.
Probably not as efficient as a system call.

Replies are listed 'Best First'.
Re: Re: What is the easiest way to copy one file to another?
by chromatic (Archbishop) on Oct 31, 2001 at 02:17 UTC
    Ugh. Use File::Copy. Or, at least, skip the slurp. :)
    open(FROM, 'file.txt') or die "Can't open file.txt: $!"; open(TO, '>copied_file.txt') or die "Can't open copied_file.txt: $!"; print TO while <FROM>;