Split words with two columns

Hi everyone, I need a little support. I have this script:

outfile = ARGV.shift

lines = ARGF.readlines
marked_up_lines = lines.map do |line|
  words = line.split
  '<mezo eazon="' + words[0] + '">' + words[1] + '</mezo>' + "\n"
end

File.open(outfile,'w') do |file|
  file.write marked_up_lines.join
end

This should split words in two columns to a HTML tag. But if I have more
then two words in the columns it cut down from the thrid word.
What should I add to see the other words? Or, does anyone have a better
script?
Regards,

Daniel

You could use shift and then join the rest:

"<mezo eazon=\"#{words.shift}\">#{words.join(' ')}</mezo>\n"

···

On 4/18/06, Dani <dan@megast.hu> wrote:

Hi everyone, I need a little support. I have this script:

outfile = ARGV.shift

lines = ARGF.readlines
marked_up_lines = lines.map do |line|
  words = line.split
  '<mezo eazon="' + words[0] + '">' + words[1] + '</mezo>' + "\n"
end

File.open(outfile,'w') do |file|
  file.write marked_up_lines.join
end

This should split words in two columns to a HTML tag. But if I have more
then two words in the columns it cut down from the thrid word.
What should I add to see the other words? Or, does anyone have a better
script?
Regards,

Daniel

Even better, just don't split them in the first place:

marked_up_lines = lines.map do |line|
  eazon, mezo = line.split($;, 2)
  "<mezo eazon=\"#{eazon}\">#{mezo}</mezo>\n"
end

Paul.

···

On 18/04/06, Farrel Lifson <farrel.lifson@gmail.com> wrote:

You could use shift and then join the rest: