Table of Contents

A simple write


open OUT, ">$out" or die "Cannot open $out for write :$!";

for $i (1..10) {
        print OUT "$i : The time is now : ",scalar(localtime),"\n";

Note the addition of > to the filename. This opens it for writing. If we want to print to the file we now just specify the filehandle name. You print to the filehandle, which is a gateway to the file.

Filehandles don't have to be capitalised, but it is wise. All Perl functions are lowercase, and Perl is case-sensitive. So if you choose uppercase names they are guaranteed not to conflict with current or future function words.

And a neat way to grab the date sneaked in there too. You should be aware that writing to a file overwrites the file. It does not append data! However, you may append: