6.8. Write to a file

Example 6-6. examples/files/write_file.pl

#!/usr/bin/perl
use strict;
use warnings;

my $filename = "report.txt";
open my $fh, '>', $filename or die "Could not open file '$filename' $!";

print $fh "Report by: Foo Bar\n";
print $fh "-" x 20;
print $fh "\n";