|
|
Listing C.10 displays the contents of a Perl script that reads the contents of a file into a Perl array in a single line.
Listing C.10 readFile2.pl
my($count) = 0; my($currentLine) = ""; my($fileName) = "somedata.txt"; open(INPUT, "<$fileName") || die "Cannot open $fileName: $!\n"; (@fileContents) = <INPUT>; $count = scalar(@fileContents); print "File $fileName contains $count lines\n";
You can launch the Perl script readFile2.pl in Listing C.10 from the command line as follows,
perl -w readFile2.pl
and the output is as follows:
File somedata.txt contains 5 lines
|
|