Marshal erro with non ascii chars

first. sorry about my english. i dont speak english very well.

please, someone help me…

i have an array with 2 colums.

ex: myfiles[1] = name of file
myfiles[2] = text of file

i used marshal.dump in this array.

later… i try use marshal.load

ex:

line 1 - scbase = File.open(source, ‘rb’) { |f| Marshal.load f }
line 2 - scbase.each do |myfiles|
line 3 - myfiles[1].gsub! ‘:’, ’ ’
line 4 - path = folder + myfiles[1] + ‘.txt’
line 5 - myfiles_text = Zlib::Inflate.inflate(myfiles[2])
line 6 - File.open(path, ‘wb’) {|file| file.write
(myfiles_text) }
line 7 - end

if the second line of array contain a file name with non asciii char,
the loop dont work.

when the line 4 is executed, the next loop is executed.

ex:

if the array contains 3 files:

1 = test
2 = test * number 2
3 = another test

the line 2 is ignored and only 2 files is created.

but there is no error.

I thought to replace * with _ before the line 5.

but the loop is aborted before. in line 4.

any ideas?

please, help-me.

Marcelo C. wrote:

if the second line of array contain a file name with non asciii char,
the loop dont work.

when the line 4 is executed, the next loop is executed.

Prove it or disprove it, by adding some printing. Here is a starting
point:

line 1 - scbase = File.open(source, ‘rb’) { |f| Marshal.load f }
STDERR.puts scbase.inspect
line 2 - scbase.each do |myfiles|
STDERR.puts “Processing #{myfiles.inspect}”
line 3 - myfiles[1].gsub! ‘:’, ’ ’
line 4 - path = folder + myfiles[1] + ‘.txt’
STDERR.puts “path = #{path.inspect}”
line 5 - myfiles_text = Zlib::Inflate.inflate(myfiles[2])
STDERR.puts “read #{myfiles_text.size} characters”
line 6 - File.open(path, ‘wb’) {|file| file.write
(myfiles_text) }
STDERR.puts “written #{path.inspect}”
line 7 - end

As you find out exactly which lines are or are not being executed, then
add further debugging.

the line 2 is ignored and only 2 files is created.

but there is no error.

Seems unlikely. Loops don’t just silently restart, and you are not
catching any exceptions.

One thought: what version of ruby are your running under?

Your example has a filename containing “*”, but that is an ASCII char.
If you really have non-ASCII characters, then ruby 1.9 may barf in
unexpected ways. But this still doesn’t explain what you describe.

First…

thank you for responding.

now,

my version is 1.8.6

and… sorry… i dont undertand very well…

obs: the “error” occurs with these characters also: à, ü, ñ, etc…

any code sugestion?

Marcelo C. wrote:

my version is 1.8.6

OK, thanks.

and… sorry… i dont undertand very well…

The question I was raising was: you said that your code fails when a
line contains a non-ASCII character, but then you said that it fails on
line 2 of the following input:

1 = test
2 = test * number 2
3 = another test

but that’s just regular ASCII. So does it fail with both?

Anyway, the best way to get help is for you to make a small, completely
standalone test program that demonstrates the issue - something which
other people can run. Then they can hack at it to uncover where the
problem lies.

any code sugestion?

You could insert those STDERR.puts that I showed you into your code, run
it again, watch it fail. Then you have some more info to work on.

I don’t believe your assertion that bits of your code are being silently
skipped. I think something else is happening. I suspect the problem is
to do with the bits of code that you haven’t posted. Hence the
importance of making a complete runnable program that demonstrates the
issue.