From: w_a_x_man Date: 2010-07-10T03:10:06+09:00 Subject: Re: FIRST PROGRAMMING PROBLEM Array On Jul 9, 12:44 pm, Francisco Martinez wrote: > unknown wrote: > > On Fri, Jul 9, 2010 at 1:22 PM, Francisco Martinez > > wrote: > >> Hi...I'm trying to solve a very simple exercise but this is one of my > >> first tasks and I can't manage to find a solution. > >> I have a txt file and I have to write a method which; given the txt file > >> as an entry argument returns an array of tokens. I have to call the > >> method that prints the solutin in the screen. > >> The solution should be this type: > > >> token 1= The > >> token 2= man > >> token 3= was > > > How far have you made it? > > * read from the file > > * get the tokens from the file > > * put the tokens into an array > > * display the output > > I think I firstly have to do sometingh like this: > > def print_tokens(txtFile) > f=File.open(txtFile) > f.each do |line| >   if(line=~/\t(.+)/) >    puts("token= #{$1}") > end > f.close > end > end > > Here I don't have any array and something to indicate the number of each > line...and it doesnt't work IO.read( "notes.txt" ).split.each_with_index{|s,i| puts "token #{i} = #{s}" }