I'm sure this problem is due to my ignorance of these issues, but I'm puzzled by this. I have a script, where I want to give the user the option of saving the output (from a database) to a file (which will eventually generate a pdf), or showing it in the browser. I'm using CGI.pm mostly for the output. I can get one or the other, but can't get both. Here's a bit of the code I'm working on:
Then there are a bunch of print statements, and the like, and then I close STDOUT.if ($query{submit} eq "PDF") { open STDOUT, ">tempfile.html" or graceful_exit("can't open fil +e"); }
Choosing to display the output ($query{submit} equals "HTML" in that case), works fine, but if PDF is chosen, the file is empty. (There are no permissions or filesystem issues.
If, instead I use the following code:
Followed by print OUTPUT statements, the file gets created fine, but there is no output to the web browser.if ($query{submit} eq "PDF") { open OUTPUT, ">tempfile.html" or graceful_exit("can't open fil +e"); } else { open OUTPUT, '>STDOUT'; # I know this is wrong }
I can't seem to find anywhere (perlopentuit or the camel book), the syntax on an open statement that allows me to open STDOUT as a regular filehandle.
I'm stumped. Because the output is generated from database output and manipluation of that data, I don't want to create redundant sets of print statements, one to a file and the other to the browser. The other option I could choose is to put this all in a subroutine, and then send the output to one or another place, depending on choice. But this seems like it ought to be straightforward.
Thanks!In reply to Redirection of output by michellem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |