Solved

Cgi write to file

Posted on 2000-05-04
3
156 Views
Last Modified: 2013-12-25
In my cgi scripts, I use code like
###################
print<<HTML;
blah,blah
HTML
####################
to print to a web page.

Is it possible to use similar code to write to a file.??

Rather than
print...
print...
over and over  again.
Thanks in advance,
Jim
0
Comment
Question by:JStan
3 Comments
 
LVL 2

Accepted Solution

by:
mattrope earned 50 total points
ID: 2777281
Yeah, just use:

print FILEHANDLE <<ENDLABEL;
blah
blah2
ENDLABEL

That should do it.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2777287
sure you can do that.

lets say you want to write to a file (/tmp/out.txt)

open(tmp, ">/tmp/out.txt") || die $!;

## You can change the currently selected filehandle with the select function.
## This function takes a single filehandle (or a scalar
## variable containing the name of a filehandle) as an argument. Once the ## currently selected filehandle is changed, it affects all
## future operations that depend on the currently selected filehandle.

select (tmp);

print<<HTML;
blah,blah
HTML
close(tmp);

## NOTE: The select operation is sticky; once you've selected a new handle, ## it stays in effect until the next select.
select (STDOUT);

0
 

Author Comment

by:JStan
ID: 2778041
Thanks for the quick reply
Jim
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 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