Gossamer Forum
Home : General : Perl Programming :

How do you use data from another file(.txt) in a cgi file?

Quote Reply
How do you use data from another file(.txt) in a cgi file?
Like if I wanted file CGI-a to print file data to data.txt. Then I want file CGI-b to get the data from data.txt that file CGI-a sent to it, and then display that data how it should be displayed to an HTML file,(like a counter or a banner rotator that stores the URL of the banners and displays it as an image) how would that code look?
I am trying to have a banner rotator have the admin file add the URL of the banners the admin entered to a form, then the form sends the data to a .txt or a log file. Then I want a display file to gather the info from the .txt file and print it to a web page.

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How do you use data from another file(.txt) in a cgi file? In reply to
does anyone know the answer?

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How do you use data from another file(.txt) in a cgi file? In reply to
To write files from cgi-a:
Code:
sub write_file{
#---------------------------------------------------------
#write files
#


$in{'info_from_form'} =~ s/\n/<br>/g;##converts line breaks to <br> tags

open(MYFILE, ">/path/to/text_file.txt");

print MYFILE $in{'info_from_form'};

close(MYFILE);
}
To open the file from cgi-b:
Code:
open(MYFILE, "/path/to/text_file.txt");

print qq|Print all of your HTML formatting here. You can also use varialbles|;

while (<MYFILE> ) {
print $_;
}
print qq|Also print here to close html tags|;

close(MYFILE);
If this file contains multiple lines, you may say $line=0
and use a foreach loop. In this case you wouldn't convert line breaks to <BR> tags until you open it.

Hope this helps..