...

View Full Version : Sorry, and also ???



Sscotties
08-22-2002, 12:20 PM
Sorry to be a pain, but I am trying to get to grips with this stuff and I am attempting to learn cgi/perl, forgive me for using this as a short-cut. What I want is something similar to this that appends the file rather than rewrites over it, so that each time it is accessed only the most recent submission is added in a new line of user input to the "results.txt" file.

#!/usr/bin/perl
open(OUT, ">/my_info/results.txt");
print "content-type: text/plain\n\n";

while (<>) {
print OUT $_;
print $_;
}
close (OUT);
exit 0;

mr_ego
08-23-2002, 05:43 AM
Instead of using ">" ... use ">>".

eg:



open(DATA,">>file.txt");
print DATA "HELLO";
close (DATA);


This is if you want to add it to the bottom of a text file.

EG:

Textfile BEFORE running the script:

my name
your name
his name
her name

Textfile AFTER running the script:

my name
your name
his name
her name
HELLO

Sscotties
08-23-2002, 10:26 AM
It's that simple eh?

Sorry, I've come accross the '>>' before and it rang some kinda bells as soon as I read your reply. I must admit, there's a wonderful simplicity about perl that it quite compelling.

You have encouraged me to take a dive into my studies just a little bit further. I'm starting to see it's appeal now.

Thank you once again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum