1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Carp; # Provides advanced method for warning or dieing
6
7 #
8 # Proper Method of opening a filehandle
9 my $file = '/Users/lhotskyb/class/Perl101/perltest.txt';
10 #open(FH, ">$file");
11 open(my $fh, '>', $file)
12 or croak "Failed to open $file: $!\n";
13
14 #
15 # Print some data to the file
16 print $fh "Test Message\n"x10;
17
18 #
19 # close the filehandle
20 close $fh;
21
22 print "Completed file write.\n";
23
24
25
syntax highlighted by Code2HTML, v. 0.9.1