Forum: Ruby split words with two columns

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E59545b25529b8ae09caffe860663296?d=identicon&s=25 Dani (Guest)
on 2006-04-18 13:55
(Received via mailing list)
Hi everyone, I need a little support. I have this script:

outfile = ARGV.shift

lines = ARGF.readlines
marked_up_lines = do |line|
  words = line.split
  '<mezo eazon="' + words[0] + '">' + words[1] + '</mezo>' + "\n"
end,'w') do |file|
  file.write marked_up_lines.join

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

05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-04-18 14:04
(Received via mailing list)
You could use shift and then join the rest:

"<mezo eazon=\"#{words.shift}\">#{words.join(' ')}</mezo>\n"
2abf5beb51d5d66211d525a72c5cb39d?d=identicon&s=25 Paul Battley (Guest)
on 2006-04-18 14:54
(Received via mailing list)
On 18/04/06, Farrel Lifson <> wrote:
> You could use shift and then join the rest:

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

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

This topic is locked and can not be replied to.