Q:
I am trying to print the contents of a file (called header.html) using a
perl script. I just can't seem to get it working. I can open the file but
I just can't print the contents. I am using the following chunk of code.
$fh = new FileHandle;
if ($fh->open("> ./header.html")) {
print "in";#debug
print <$fh>;
$fh->close;
}
Any suggestions would be appreciated.
A:
print "in"
prints to the standard output.
print <$fh>;
prints a line read from the file (which is actually undef as the file was
opened for output) to the standard output.
To print something into the file you have to
print $fh "string"
(note there is no comma after $fh)
Regards,
Peter
[ back to toc ]