# File: file1.pl # Title: FILES - read only one line and split in words # Author: Mihaela Malita # File test0.txt consists of: # Sir Isaac Newton # Blaise Pascal # Renee Descartes # >perl file1.pl # Reads first line: test0.txt # First line read is: Sir Isaac Newton # Has 3 words: # Sir # Isaac # Newton $filename = "test0.txt"; print "\nReads first line: $filename"; open(IN,$filename); # Missing: you should check if file is there $r = ; # reads first line in a string @A = split(" ",$r); # transforms line in words $len = @A; # length of array close IN; # close file, so you can do other operations print "\nFirst line read is: $r"; print "Has $len words: \n $A[0] \n $A[1] \n $A[2]"; exit;