Solved

Appending to a file...

Posted on 2000-04-17
2
196 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
Comment Utility
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
Comment Utility
 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now