Link to home
Start Free TrialLog in
Avatar of JStan
JStan

asked on

Cgi write to file

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
ASKER CERTIFIED SOLUTION
Avatar of mattrope
mattrope

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maneshr
maneshr

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);

Avatar of JStan

ASKER

Thanks for the quick reply
Jim