# File: file2.pl # Title: Read a text file and prin the vocabulary sorted. # Author: Mihaela Malita # Here is the file mary.txt: # Mary had a little lamb, # It's fleece was white as snow. # And everywhere that Mary went # The lamb was sure to go.... # Name of file? mary.txt print "Name of the file (mary.txt)? "; $filename = ; chop($filename); # read from keyboard @S = readFile2Array($filename); # all file in array, one line = one element $len = @S; #how many lines (elements) print "Text in array\n @S \n has $len lines"; exit; sub readFile2Array { my ($fin) = @_; # name of the text file from main unless (open(IN,"$fin")) { # check if the file exists print "No file with such a name!"; exit; } my @R = ; # read all text file in a huge array! line = element close IN; # close file return @R; # return array }