[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: add to words syntaxes

Dani

3/16/2006 1:08:00 PM

Hi again!
Thanks for ALL your support, especially for Carlos. now it works fine!
Only one more question and I leave this theme.
What is if I in my TXT file the parameters repeat self?
So I mean:
0608A;
Teszt Kft;
33445566222;
;
20060101;
20060131;
0A0001C002A 33445566222
0A0001C007A Teszt kft

0608M
Oscar Wild
123456789
;
20060101;
20060131;
0A0001C002A 33445566222
0A0001C007A Teszt kft

etc.. So I need, that on the end of the first paragraph it looks for the
second. How can I do this? With the same syntax, same file.
Regards:

Daniel

-----Original Message-----
From: Carlos [mailto:angus@quovadis.com.ar]
Sent: Thursday, March 16, 2006 12:26 PM
To: ruby-talk ML
Subject: Re: add to words syntaxes


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/Manual/man-1.4/sy...
here_doc

[...]

> 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


1 Answer

Carlos

3/16/2006 3:15:00 PM

0

Dani wrote:
[...]
> What is if I in my TXT file the parameters repeat self?
> So I mean:
> 0608A;
> Teszt Kft;
> 33445566222;
> ;
> 20060101;
> 20060131;
> 0A0001C002A 33445566222
> 0A0001C007A Teszt kft
>
> 0608M
> Oscar Wild
> 123456789
> ;
> 20060101;
> 20060131;
> 0A0001C002A 33445566222
> 0A0001C007A Teszt kft
>
> etc.. So I need, that on the end of the first paragraph it looks for the
> second. How can I do this? With the same syntax, same file.
> Regards:

# Set the "input record delimiter" to "paragraph". This is
# a special case and you weren't expected to know it beforehand :)

original_delimiter = $/
$/ = ""

# ... read the "lines" (chunks of text between <newline><newline>) ...

chunks = ARGF.readlines

# ... and restore the IRS to <newline>

$/ = original_delimiter

# now extract individual lines from each chunk and process them as before

chunks.each do |chunk|
lines = chunk.split($/)
... < the previous code > ...
end

HTH - (not tested)