shay has asked for the wisdom of the Perl Monks concerning the following question:
What is the best way to copy a file to a temporary file?
(The purpose of the temporary file is to read data from, process it in some way, and then write it back over the top of the original file; i.e. I effectively want to edit the original file "in-place", but not all in memory at once in case it is too large.)
I was intending to use the File::Temp::tempfile() function to get a temporary file, and File::Copy to do the copying, but both of the following obvious ideas have problems:
-
my $tmpfh = File::Temp::tempfile(); File::Copy::copy($file, $tmpfh);
-
my($tmpfh, $tmpfile) = File::Temp::tempfile(UNLINK => 1); File::Copy::copy($file, $tmpfile);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Copying a file to a temporary file
by tachyon (Chancellor) on Jun 15, 2004 at 13:15 UTC | |
Re: Copying a file to a temporary file
by Aragorn (Curate) on Jun 15, 2004 at 13:26 UTC | |
Re: Copying a file to a temporary file
by BrowserUk (Patriarch) on Jun 15, 2004 at 13:26 UTC | |
by shay (Beadle) on Jun 16, 2004 at 11:53 UTC | |
by BrowserUk (Patriarch) on Jun 16, 2004 at 13:05 UTC | |
by shay (Beadle) on Jun 16, 2004 at 16:01 UTC | |
by BrowserUk (Patriarch) on Jun 16, 2004 at 17:53 UTC | |
|
Back to
Seekers of Perl Wisdom