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.
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.