From: Joel Pearson Date: 2013-02-14T07:48:55+09:00 Subject: Re: file size of each item in file list Sloan Ruby wrote in post #1096778: > I am trying to take the contents of a file which contains the results of > a file size search and print those out with ruby. To obtain the file > size of each line in that file. > > #!/usr/bin/ruby > > f = File.open("/tmp/lg_files") do this in a block so it closes the file afterwards: File.read("/tmp/lg_files") do |f| > contentsArray=[] # start with an empty array > f.each_line {|line| > a = contentsArray.push line where did "a" come from? You already have a variable storing this information: contentsArray. > #b = File.size(a) try "File.size contentsArray.last" instead > puts a > } > > > This results in each line in the file /tmp/lg_files printing. -- Posted via http://www.ruby-forum.com/.