On 2005.12.26, at 10:09 PM, John Delacour wrote:
At 9:10 am +0900 26/12/05, Joel Rees wrote:
I note your are running both the script and the HTML in Unicode
UTF-8. There is wisdom in that, of course, and I may rethink my
choice of running these scripts in shift-JIS. (I like to avoid
conversions that require tables and context decisions as much as
possible.)
I simply hate legacy encodings. Having worked with Chinese on the Mac
since system 6, I would have switched to Windows NT if Apple had not
finally implemented Unicode in Mac OS 10. Having waited so long for
Unicode, I use nothing else now.
I'll have to tell you a war story or two, sometime.
Unicode is a kludge. It's one of the better kludges, and evidence that
kludges make the world go round, but it's still a kludge. (I have
nothing against most kludges, especially kludges that work relatively
well, but I will call a kludge a kludge.)
I also notice you are saving the file back to disk so you can re-open
it as shift-JIS. I want to avoid that, since perl is already saving
it once to a temporary directory anyway...
Yes, my script was simply a very badly implemented proof of concept.
Having looked at the question more deeply, I'm now half way through
doing a proper job making proper use of CGI.pm.
Ah!
(Muttering to self -- can perl open strings as streams like Java?)
Yes.
I just noticed an example in the Cookbook -- recipe 8.23.
I have now had a better look at CGI.pm and come up with a solution
that works, I think, as you want it. The curious thing is that some
browsers had no difficulty even before I used Encode->from_to.
To see the script go to <http://bd8.com/temp/> and view uploadj.pl.txt
To try it out go to:
<http://ccgi.bd8.com/cgi-bin/uploadj.pl>
I'm going to take a long, slow look at that tomorrow. (The frustrating
thing about this is that I've been here before, about three years back
when the perl implementation wasn't quite as complete, but I can't
remember what I did, and I don't have access to the code I built then
anymore.)
At 2:27 am +0000 26/12/05, John Delacour wrote:
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
Clearly the Christmas goose had affected my reason!
Ahah! (And I thought you were just politely telling me to look a little
further in perldoc and ask better questions. ;-)
As you were about to tell me, CGI.pm has already opened the file
handle; so if you want to avoid writing the contents to another file
and then opening that as above, it is necessary to use Encode as shown
<http://bd8.com/temp/uploadj.pl.txt>
JD
from_to( $line, Shift_JIS, Shift_JIS)?
It's midnight. I'll look at it tomorrow.
Thanks.
Joel