Solved

Appending to a file...

Posted on 2000-04-17
2
220 Views
Last Modified: 2010-03-05
 I am currently using a perl script to store form data on a server, it keeps all the data by first opening the file and reading out all the data then printing it all back in, plus the new line at the bottom... (very sad I know...) like this:

      open(BUFFER,"<$MBUKstor") or explode ("Cannot open $MBUKstor at line 25 - $!");
            push @lines, <BUFFER>;
      close(BUFFER);

      open(STORE,">$MBUKstor") or explode ("Cannot open $MBUKstor at line 29 - $!");
            foreach $line (@lines) {
                  print STORE "$line\n";
            }
            print STORE "$FORM{'name'} |:| $FORM{'email'} |:| $FORM{'postcode'} |:| $FORM{'conly'}\n";
      close(STORE);

But I want to just print the new line at the end of the file, what is the code to append to the end of the file???

Regards
JB

0
Comment
Question by:JavaBloggs
2 Comments
 
LVL 10

Accepted Solution

by:
makerp earned 300 total points
ID: 2722354
use a double >> in the open for appending rather than write and destroy if already there

open(STORE,">>$MBUKstor") or explode ("Cannot open $MBUKstor at line 29 - $!");

print STORE "$line\n";

hope thus helps
 
0
 

Author Comment

by:JavaBloggs
ID: 2722375
 Cheers for that, I know its not worth 300 pts, but I was in a hurry and left my books at home....

  Thanks again
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question