Alex Gutteridge
10/17/2007 4:13:00 AM
On 17 Oct 2007, at 11:49, Tj Superfly wrote:
> Thanks Ben!
>
> I really appreciate your help, and feel bad asking this, but would you
> (or someone else) be willing to put this together for me and post the
> code here?
>
> I'm a 16 year old and still actually learning ruby in school, so
> 1/2 of
> what you said Ben made no sense what so ever to me. :P
Don't take this the wrong way, but you will learn far more
implementing it yourself (with help if need be) than getting someone
else to do it for you. Anyway, what you have so far looks good, you
just need to keep going.
> I've created 2 files with the names you have there, like you
> suggested.
> Here are their locations. This is actually what I don't understand the
> most is this whole file thing, I think that's what throwing me off the
> most. Anyway, here are their locations:
>
> C:\Documents and Settings\nonstickglue\My Documents\TDN\urls.txt
> C:\Documents and Settings\nonstickglue\My Documents\TDN
> \urls_checked.txt
>
Do you mean you don't understand how to read/write files in Ruby?
There are many possibilities, but Ben showed you two techniques which
will work. The code below reads through each line of one file
(urls.txt) and writes it to the other (urls_checked.txt) if the test
in the url_ok? method returns true. I don't really understand what
you what do with these URLs but I've just used a modified version of
the code you pasted as an example. Perhaps you can make progress from
there.
def url_ok?(url)
puts "Is this URL OK? - Answer yes or no"
delete_url= gets.chomp
if(delete_url == "yes")
return true
elsif(delete_url == "no")
return false
end
end
File.open('C:\Documents and Settings\nonstickglue\My Documents\TDN
\urls_checked.txt','w') do |out|
File.foreach('C:\Documents and Settings\nonstickglue\My Documents
\TDN\urls.txt') do |line|
out.puts line if url_ok?(line.chomp)
end
end
> ----
>
> I also have no idea what TK dialog box is or anything. Basically I'm
> going to be running this program via command promt, I'm not using Ruby
> on Rails, I'm just working with Ruby. So just a simple
Tk is a kind of GUI, so perhaps don't worry about that now.
>
> puts "Would you like to delete this URL from the file? - Answer yes or
> no"
> delete_url= gets.chomp
> if(delete_url == "yes")
> # some code that deletes the url from the here
> puts "The url has been removed from the list."
> elsif(delete_url == "no")
> # maybe some code here, I really have no idea
> puts "The url has been left in the file and the program will continue
> running now."
> end
>
> I dunno. Like I said I'm new at this, so this might be to big of a
> project for me to tackle, but I can only get better from trying. :D
> Thanks again for all your help.
Try taking small steps and break the problem down. Try reading/
writing files, then asking for input, then developing the logic, then
testing URLs etc... And when asking for help keep your question short
and specific. People are much more likely to answer a short concise
question like 'how do I read a file?' than 'I want my program to do
X, please write it for me'.
Alex Gutteridge
Bioinformatics Center
Kyoto University