|
-
December 7th, 2006, 11:24 PM
#1
Junior Member
Writing to files..
Hi,
please help me out with this code.
I want to enter new text in a file specified by the user, and transfer the old data into another file named oldfile.txt
It only writes to the specified file, but doesn't save the old data in oldfile.txt
Here is the result on execution
____________________________________________________________
#>perl openpage.pl
Welcome.. Enter a file name to rewrite:text.txt
Cant write to olddata at openpage.pl line 13.
_________________________________________________________
#openpage.pl follows..
use strict;
print"\nWelcome.. Enter a file name to rewrite:" or die"Cant ask";
my $file=<> or die"Cant ask 2";
open (PAGE,">$file") || die "Cannot open file.";
my @olddata=<PAGE> or die"Cant write to olddata";
print "The file contains the following data:\n" or die"cannot show";
foreach(@olddata){
print or die"Cannot show old things";}
print"\nEnter new data:\n";
my @data=<>;
open (CPY, ">>oldfile.txt") or die"Cant open to oldfile";
print CPY @olddata or die"Cannot write to oldfile";
print PAGE @data;
close PAGE;
close CPY;
______________________________________________________________________________
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|