ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: wired result
by Cheyne Li other posts by this author
May 8 2008 2:47PM messages near this date
Re: wired result | scramble sentence, how to better program?
Michael Linfield wrote:
>  If I'm understanding you correctly, you have lets say an array of keys 
>  you want to find in a file.
>  
>  fileKeys = ["key1","key44","key5"]
>  
>  lets just say the file contains a bunch of useless jargon and some keys:
>  
>  testfile.txt #
>  
>  stuff
>  more stuff
>  key5
>  useless junk
>  more useless junk
>  not a key
>  key44
>  
>  
>  Ok, now lets read that file and put the keys in an array called results
>  
>  results = []
>  
>  IO.foreach("testfile.txt") {|x| results << x.chomp}
>  => nil
>  
>  Now we compare the arrays to find any matches
>  
>  results&fileKeys
>  => ["key5","key44"]
>  
>  Regards,
>  
>  - Mac


Hi, Mac

My program is not that complex though.
The file has format like this:

C:\Documents and Settings\cheynel\Desktop\p001hello.txt,puts
C:\Documents and Settings\cheynel\Desktop\hello.rb,print
C:\Documents and Settings\cheynel\Desktop\04.rb,Thank
C:\Documents and Settings\cheynel\Desktop\read.rb,print
C:\Documents and Settings\cheynel\Desktop\class.rb,class
C:\Documents and Settings\cheynel\Desktop\reg.rb,cheyne

So, basically, each line has 2 arguments,which is seperated by ","

the first argument is the location of the test fils, and the second one 
is the key word to match corresponding the file. such as, "puts" is need 
to be found in poo1hello.txt, not need to be found in hello.

Well, the problem is solved, I found the string read in from a file will 
automatically attached with something, which I'm quite sure if it is 
newline. but use str.chop! will solve it.

Anyway, Thank you for your reply
-- 
Posted via http://www.ruby-forum.com/.
Thread:
Cheyne Li
Cheyne Li
Che
Michael Linfield
Cheyne Li

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved