Forum: Ruby word split with 2 columns

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dani (Guest)
on 2006-03-15 19:18
(Received via mailing list)
Hi everyone!
I need a little help. I have a script for ruby:

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 script should split two words with special parameter (from a plain
text it makes xml source). That works so fine if I have ONLY two
columns, but if I put several lines in the txt file beginning it dies.
So, my only question is: how can I bring ruby that it should from line
nr. X (i.e. 6 or 7) begin? And another question: can ruby after the
conversion put in the file a line (ie. </end>)?
Thanks, regards:


Daniel
removed_email_address@domain.invalid
ChrisH (Guest)
on 2006-03-15 20:01
(Received via mailing list)
Dani wrote:
>
> File.open(outfile,'w') do |file|
>   file.write marked_up_lines.join
> end
>
>
> This script should split two words with special parameter (from a plain
> text it makes xml source). That works so fine if I have ONLY two
> columns, but if I put several lines in the txt file beginning it dies.
> So, my only question is: how can I bring ruby that it should from line
> nr. X (i.e. 6 or 7) begin?
....
start_line = 6 #or 7, or whatever...
marked_up_lines = lines[start_line..-1].map do |line|
....

>And another question: can ruby after the
> conversion put in the file a line (ie. </end>)?
File.open(outfile,'w') do |file|
   file.write marked_up_lines.join
   file.write '</end>'
end

cheers
This topic is locked and can not be replied to.