Forum: Ruby Re: add to words syntaxes

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-16 12:51
(Received via mailing list)
If I understand you well the script should look like this:

outfile = ARGV.shift

lines = ARGF.readlines

nyomtatvanyazonosito, nev, adoszam, adoazonosito, tol, ig =
    lines.slice!(0,6).map {|w| w.chomp.chomp(';') }
first_six_data = <<-EOT
'<?xml version="1.0" encoding="windows-1250"?>'
'<nyomtatvanyinformacio>'

'<nyomtatvanyazonosito>'#{nyomtatvanyazonosito}'</nyomtatvanyazonosito>'
      '<adozo>'
        '<nev>'#{nev}'</nev>'
        '<adoszam>'#{adoszam}'</adoszam>'
        '<adoazonosito>'#{adoazonosito}'</adoazonosito>'
      '</adozo>'
      '<idoszak>'
        '<tol>'#{tol}'</tol>'
        '<ig>'#{ig}'</ig>'
      '</idoszak>'
'</nyomtatvanyinformacio>'
'<mezok>'
EOT

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

But if i run it so in the ouput only the things after the first six
lines appear....

Daniel
Carlos (Guest)
on 2006-03-16 13:28
(Received via mailing list)
Dani wrote:

> If I understand you well the script should look like this:
>
> outfile = ARGV.shift
>
> lines = ARGF.readlines
>
> nyomtatvanyazonosito, nev, adoszam, adoazonosito, tol, ig =
>     lines.slice!(0,6).map {|w| w.chomp.chomp(';') }
> first_six_data = <<-EOT
> '<?xml version="1.0" encoding="windows-1250"?>'

Why the quotes here? The string is everything between the line following
"<<-EOT" and "EOT". See
http://www.ruby-doc.org/docs/ruby-doc-bundle/Manua...

[...]

> File.open(outfile,'w') do |file|

# You forgot to write the variable first_six_data here.
     file.write first_six_data
>   file.write marked_up_lines.join

# And here probably you need to write
     file.write "</...></...></...>"
> end

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