From: Alexander Santoro Date: 2010-04-08T08:02:46+09:00 Subject: First post Hello I am new to Ruby and programming. I hate to just dump code here so if you don't feel like responding I understand. I am trying to import two text files, one containing names and one containing text. I did this using : --------------------------------------------------------------------------- def namez $fbNamez = [] nf = File.open("names.txt", "r") nf.each_line { |line| $fbNamez.push line } nf.close puts $fbNamez end ----------------------------------------------------------------------------- def threadz $fbThreadz = [] tf = File.open("thread.txt", "r") tf.each_line { |line| $fbThreadz.push line} tf.close puts $fbThreadz end ------------------------------------------------------------------------------ I know this cannot be the best way to do this but it was all I muster. The goal was to iterate through the array of names and extrapolate data relative to the thread.txt file. Example: The names.txt file reads as so: John Doe Jane Doe Donald Duck Donald Notreal Mike Mikes The threadz.txt reads as so: -------------------------------------------------------------------------------- John Doe March 9 at 4:09pm Reply ok so who likes steph more than Sonia..... cuz i do Jane Doe March 9 at 4:13pm Reply hahahahah what aaaan asshole John Doe March 9 at 4:18pm Reply hhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaa Donald Duck March 9 at 4:50pm Reply seriously, lets take a vote all in favor say I Donald Notreal March 9 at 4:51pm Reply aye Mike Mikes March 9 at 4:52pm Reply aye.. dont give a shit really ------------------------------------------------------------------------------ I would like to learn how to make this program grab the first name in the array, use it to search the thread.txt for posts using the name as a delimiter? I want to have it return results for: how many posts? who posted the most? who posted the least? who said the most bad words? Searching for text. How can I teach my program to recognize posts? Can the date and time be manipulated or used to my advantage? I am currently using "Beginning Ruby" by Peter Cooper. Here is the ugly code..... sorry once again. --------------------------------------------------------------------------------///////////////ThreadReader1.0\\\\\\\\\\\\\\\\\\\\\\\\\ class Texfun #Names Array values = 0 - 20 def namez $fbNamez = [] nf = File.open("names.txt", "r") nf.each_line { |line| $fbNamez.push line } nf.close puts $fbNamez end #Thread Array ~~~~Values 0-1913~~~~~~ def threadz $fbThreadz = [] tf = File.open("thread.txt", "r") tf.each_line { |line| $fbThreadz.push line} tf.close puts $fbThreadz end #Number of Posts def post_counter text = $fbThreadz.join total_posts = "Total Number of posts: #{text.split("Reply").length}" end #name finder def look e = gets.to_i puts $fbNamez end end printer = Texfun.new printer.look ------------------------------------------------------------------------------------------- Any insight would be appreciated. Thanks in advance. -- Posted via http://www.ruby-forum.com/.