[ back to toc ]

Printing files in perl

Date: 2002/05/20 10:37

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

Any suggestions would be appreciated.
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)


[ back to toc ]