Count number of lines in a file

Write a Ruby program which counts number of lines in a files.
countLines.rb
fp = File.open("countLines.rb", "r")
if fp
ary = IO.readlines("countLines.rb")
print("#{ary.length} lines in the file.")
else
print("File does not exists.")
end
OUTPUT
7 lines in the file.

No comments:

Post a Comment

Total Pageviews