[Techtalk] [Perl] cgi.pm - save input in .html file

Kai MacTane kmactane at gothpunk.com
Tue Jan 9 19:03:26 UTC 2007


At 10:22 AM 1/9/2007, Michelle Murrain wrote:

>Open a file handle like:
>
>open(FILE, "test.html") or print p, "Can't write to test.html";

If you're going to write to it, you need to add the > symbol:

open(FILE, ">text.html")

Note that this version will "truncate the file" (nifty techspeak for 
"throw away everything inside it") and effectively start a clean, new 
file from scratch. If you wanted to append to the file instead of 
overwriting it, use two >s, so:

open(FILE, ">>text.html")

I think that, in the Camel Book, Larry Wall says something like: "by 
a curious coincidence, these are the same symbols used for Unix shell 
redirection". Yeah, I'm sure it was just a complete accident that it 
worked out that way. :)

                                                 --Kai MacTane
----------------------------------------------------------------------
"The night is my companion, and solitude my guide."
                                                 --Sarah McLachlan
                                                  "Possession" 




More information about the Techtalk mailing list