excel data manipulation through Ruby

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrjnyc1234
    New Member
    • Feb 2008
    • 1

    excel data manipulation through Ruby

    Here's what I'd like to do

    have a list of any number of words in excel in a column.

    have another list of any number of words in another column

    I want to take each word from List A and concatenate it with each word in list B.

    So if list A had:

    pumpkin
    birds
    hawks
    seafood


    and if list B had:

    fast
    scream
    wow

    the script would produce
    pumpkin fast
    pumpkin scream
    pumpkin wow
    birds fast
    birds scream
    birds wow
    hawks fast
    hawks scream
    hawks wow
    seafood fast
    seafood scream
    seafood wow

    I don't need a GUI, just something I can execute from the command prompt. I know a little bid about ruby so I know this is just some basic array manipulation and concatenation.. .any takers?

    Thanks,

    J
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    You would want to do a loop within a loop. Loop through list A, and for each element in list A, loop through list B and concatenate.
    [CODE=ruby]list_a.each{|a| list_b.each{|b| puts a.to_s + b.to_s}}[/CODE]

    Comment

    Working...