Reading File Contents into an Array

   



Print File Contents in Reverse Order

Listing C.25 reverseOrder1.pl

start example
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
end example



   



Fundamentals of SVG Programming. Concepts to Source Code
Fundamentals of SVG Programming: Concepts to Source Code (Graphics Series)
ISBN: 1584502983
EAN: 2147483647
Year: 2003
Pages: 362

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net