Do you know of a way to tell perl, or, rather, the CGI module to open the file handle as shift-JIS?

open F, "<:encoding(shift_jis)", $f

Okay, okay, I see I have shown my laziness.

However, I have just dug into chapter 8 of the Cookbook (Second edition) and found a couple of relevant bits, and

    use open IO => ":raw :encoding(Shift_JIS)";

at the top of the script, before the "use encoding( 'Shift_JIS' );" and

    binmode( $fh, ":raw :encoding(Shift_JIS)" );

immediately after grabbing the file handle with "$fh = $query->upload( 'file-to-send' )" do not help. They do seem to alter the error messages in apache's error_log.

So, here's the error messages, and the output where I should be getting

    空欄を埋めたり、完全な文書で質問に答えたり、一番適切に思う解答を〇で記したりする。

Error messages with neither of the above attempts to push the io layers around:

-----------errors----------
Wide character in print at (eval 10) line 85.
"\x{fffd}" does not map to shiftjis at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 281, <fh00001Sample_questions.text> line 38.
-----------------------------
with the second line repeated six times.
-----------output----------
遨コ谺\x{fffd}繧貞沂繧√◆繧翫\x{fffd}∝ョ悟\x{fffd}ィ縺ェ譁\x{fffd}譖ク縺ァ雉ェ蝠上↓遲斐∴縺溘j縲∽ク \x{fffd}逡ェ驕ゥ蛻\x{fffd}縺ォ諤昴≧隗」遲斐r縲\x{fffd}縺ァ險倥@縺溘j縺吶k縲
-----------------------------

With the 'use open IO => ":raw :encoding(Shift_JIS)";' uncommented, the result:

-----------errors----------
Wide character in print at (eval 11) line 85.
"\x{fffd}" does not map to shiftjis at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 281, <fh00001Sample_questions.text> line 38.
-----------------------------
again, with the second line repeated six times.
-----------output----------
遨コ谺\x{fffd}繧貞沂繧√◆繧翫\x{fffd}∝ョ悟\x{fffd}ィ縺ェ譁\x{fffd}譖ク縺ァ雉ェ蝠上↓遲斐∴縺溘j縲∽ク \x{fffd}逡ェ驕ゥ蛻\x{fffd}縺ォ諤昴≧隗」遲斐r縲\x{fffd}縺ァ險倥@縺溘j縺吶k縲
-----------------------------

Almost exactly the same. This is also the results when I use binmode raw on the file handle for the upload.

With the "use open IO ... " commented out and the 'binmode( $fh, ":raw :encoding(Shift_JIS)" );' uncommented, the results are

-----------errors----------
Wide character in print at (eval 10) line 85.
shiftjis "\x84" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x80" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x85" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x87" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x80" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x87" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x87" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x82" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212.
-----------------------------
-----------output----------
遨コ谺\x84繧貞沂繧√◆繧翫\x80∝ョ悟\x85ィ縺ェ譁\x87譖ク縺ァ雉ェ蝠上↓遲斐∴縺溘j縲∽ク\x80逡ェ驕ゥ蛻\x87縺ォ諤昴≧ 隗」遲斐r縲\x87縺ァ險倥@縺溘j縺吶k縲\x82
-----------------------------

And, with both uncommented, the results are

-----------errors----------
Wide character in print at (eval 11) line 85.
shiftjis "\x84" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x80" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x85" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x87" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x80" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x87" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x87" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212. shiftjis "\x82" does not map to Unicode at /Volumes/web/userweb/joel/cgi/cs/ranbunhyou/withfile2 line 212.
-----------------------------
-----------output----------
遨コ谺\x84繧貞沂繧√◆繧翫\x80∝ョ悟\x85ィ縺ェ譁\x87譖ク縺ァ雉ェ蝠上↓遲斐∴縺溘j縲∽ク\x80逡ェ驕ゥ蛻\x87縺ォ諤昴≧ 隗」遲斐r縲\x87縺ァ險倥@縺溘j縺吶k縲\x82
-----------------------------

Looks like I'll need to get a hexdump from perl to get a better handle on this, or perhaps try the script on a Linux box, but I've got to get some sleep tonight. Taking the kids to the doc and to piano practice didn't leave much time to work on it today.

I'm suspecting the problem lies in the incomplete implementation of locales in Jaguar, or perhaps in my choice of locales when I compiled perl on this box.

Reply via email to