Ruby Forum Test > problem with the for loop

Posted by Vidya Vidya (vidyagayathri)
on 12.10.2007 09:38
Hi all,

   i have problem with the for loop, my problem is first i have to read
the file from the directory, after reading the file i have count the
number of data and need to insert in the db, that work i finihsed, but
while reading data, each every record i have "~", so by using "~" i will
split the the records, but at the last record which is present in the
file atlast if i remove the "~" only it shows the corrects data
otherwise it shows one more empty records, so please let me know how to
avoid.

example:

directory name = sample
it contanins 2 files, that is test1,test 2
inside the test1:

LIN*EDIA000005*000000570*570*0697~
LIN*EDIA000005*000000570*570*0698~
LIN*EDIA000005*000000570*570*0699~
LIN*EDIA000005*000000570*570*0700~  (here if i remove the "~" only i
will get the answer)

test 2:
LIN*EDIA000005*000000570*570*0701~
LIN*EDIA000005*000000570*570*0702~ (like this here also)


my coding is:

 Dir["#{sample}/**/**"].each do | thisfile |
             f = File.open(thisfile,"r")
             @fread=f.read()
             @adiv=@fread.split("~")   //spliting the record
             @adiv.each do |v|
             @h=v.split("\*")  //split the data
              // store data in db

             end
 end



   please let me know, how to solve this problem, thanks in advance