in reply to Create html file from script

Hi dtharby,

Please be aware that you are attempting to open an INPUT file, (even though the filehandle is called OUTPUT).  That's because the default mode of open is "read".

To open a file for output, you should do either:

open(OUTPUT, ">$outputFile");

Or even better...

open(OUTPUT, ">", $outputFile);

And best of all, because it checks for an error condition:

open(OUTPUT, ">", $outputFile) or die "Failed to write to '$outputFile +' ($!)\n";

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Create html file from script
by ww (Archbishop) on Jul 18, 2006 at 17:14 UTC
    ++, Liverpole and ditto to explorer

    Code below is based on the guess that that OP is trying to create a static file ...and, at that, perhaps only on a non-server box:

    #!usr/bin/perl -w use strict; use vars qw($out); $out = "test060718.htm"; open( OUTPUT, ">", "$out") or die "Can't open $out \n"; # Send content-type -- NOT needed if sending to a file # print "content-type: text/html \n\n"; # OUTPUT Header Section # print OUTPUT "<html>\n"; print OUTPUT "<head>\n"; print OUTPUT "<title>Created By Perl</title>\n"; #\title fixed to /title as per [explorer] 's node, below print OUTPUT "</head>\n"; # HTML Body # print OUTPUT "<body>\n"; print OUTPUT "foo\n<h1>bar</h1>\n</body></html>\n";

    produces:

    <html> <head> <title>Created By Perl</title> </head> <body> foo <h1>bar</h1> </body></html>