On Mar 7, 2007, at 9:33 AM, Samantha wrote:

> This is what I have so far that I found from someone's blog (I got  
> the concept from someone's blog...

> File.open("i put the filename here").each do |record|
>  record.split("|").each do |field|
>    field.chomp!
>    puts field
>  end
> end
>
>
> So, what I want it to do, is say I have the following fields in the  
> | delimited file:
>
> category | subcategory | description
>
> How do I make that stuff into a hash?  I should probably start out  
> small by putting it into a hash first, and then figure out how to  
> deal with it in MySQL.

Let me try giving you this little hint and see if it's enough:

 >> cat, sub, des = "Books|Programming|A fun book about Ruby".split("|")
=> ["Books", "Programming", "A fun book about Ruby"]
 >> cat
=> "Books"
 >> sub
=> "Programming"
 >> des
=> "A fun book about Ruby"

Don't be shy if you need more help!

> If someone could point me in the right direction, of possible  
> libraries that would help or the such, I'd love to go read there  
> and study on it and try to figure it out.  Not asking for answers,  
> just asking for resources. :)

The standard CSV library will do the parsing for you, but this case  
looks very simple so you probably don't need it.  However, if the  
first row of the file has the field names, it might be worth looking  
at FasterCSV which will build the Hashes for you:

http://rubyforge.org/projects/fastercsv/

Hope that helps.

James Edward Gray II