Home > Archive > PERL Beginners > April 2007 > how to create copy of a original file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to create copy of a original file
|
|
|
| Hi:
My perl program run creates a data file everytime its run is scheduled. I
need to backup the data file everytime i run it so i have a copy of the
original data file. How can i create a copy of this file in my perl program
before it gets updated. I am taking this file as user input from the command
prompt.
Thanks!
| |
| Paul Lalli 2007-04-18, 6:58 pm |
| On Apr 18, 6:13 pm, nishipraf...@gmail.com (Nishi) wrote:
> My perl program run creates a data file everytime its run is scheduled. I
> need to backup the data file everytime i run it so i have a copy of the
> original data file. How can i create a copy of this file in my perl program
> before it gets updated. I am taking this file as user input from the command
> prompt.
I can think of three ways off the top of my head. . .
# 1)
system('cp', $file, "$file.old");
# 2)
use File::Copy;
copy ($file, "$file.old");
# 3)
open my $fh, '<', $file or die "Cannot open $file: $!";
open my $copy_fh, '>', "$file.old" or die "Cannot open $file.old: $!";
print $copy_fh $_ while <$fh>;
Paul Lalli
| |
|
| I got it. using File::Copy
Thanks!
On 4/18/07, Nishi <nishiprafull@gmail.com> wrote:
>
>
> Hi:
>
> My perl program run creates a data file everytime its run is scheduled. I
> need to backup the data file everytime i run it so i have a copy of the
> original data file. How can i create a copy of this file in my perl program
> before it gets updated. I am taking this file as user input from the command
> prompt.
>
> Thanks!
>
| |
|
|
|
|
|