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.
Dani (Guest)
on 2006-04-18 15: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

Farrel L. (Guest)
on 2006-04-18 16:04
(Received via mailing list)
You could use shift and then join the rest:

"<mezo eazon=\"#{words.shift}\">#{words.join(' ')}</mezo>\n"
Paul B. (Guest)
on 2006-04-18 16:54
(Received via mailing list)
On 18/04/06, Farrel L. <removed_email_address@domain.invalid> 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.