|
|
Listing C.25 reverseOrder1.pl
my($fileName) = "somedata.txt"; my($currentLine) = ""; my($result) = ""; my($index) = 0; my($lineCount) = 0; my(@fileContents); open(INPUT, "<$fileName") || die "Cannot open $fileName: $!\n"; (@fileContents) = <INPUT>; $lineCount = scalar(@fileContents); for($index=$lineCount-1; $index>=0; $index--) { $currentLine = $fileContents[$index]; print "$currentLine"; }
You can invoke the Perl script arrayFile1.pl from the command line as follows,
perl -w arrayFile1.pl
and the output will be as follows:
Smith:Bill:3000 Smith:Ann:2000 Jones:Tom:1000 # this is a comment line
|
|