Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-22-2002, 12:20 PM   PM User | #1
Sscotties
New Coder

 
Join Date: Aug 2002
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Sscotties is an unknown quantity at this point
Sorry, and also ???

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;
Sscotties is offline   Reply With Quote
Old 08-23-2002, 05:43 AM   PM User | #2
mr_ego
Regular Coder

 
Join Date: Jun 2002
Location: Brisbane, Australia
Posts: 181
Thanks: 1
Thanked 0 Times in 0 Posts
mr_ego is an unknown quantity at this point
Instead of using ">" ... use ">>".

eg:

Code:
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

Last edited by mr_ego; 08-23-2002 at 05:48 AM..
mr_ego is offline   Reply With Quote
Old 08-23-2002, 10:26 AM   PM User | #3
Sscotties
New Coder

 
Join Date: Aug 2002
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Sscotties is an unknown quantity at this point
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.
Sscotties is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:34 PM.


Advertisement
Log in to turn off these ads.