Howdy, # Perly ;-?
### What I'm trying to do (the socket part) ###
I wrote in Perl CGI app for Xitami web server, which (my app) is LRWP
(Long_Running_Web_Process) - it does 'socket/connect' with web server on
startup and then sysread/syswrite to talk to the web server to handle requests
(output is in XML encoded in UTF-8), so if user points its web browser to
http://my_host/xmlData?arg=flows, it is feeded with xml data. # Actually, I've
taken an example of LRWP and modified it to suit my needs.
### Where's the problem? Working non-elegant, long solution [A] ###
I have to convert some texts from win-cp1250 to UTF-8, to properly send it xml.
First, I've did it like this (and this way it is working!):
<Perl>
require 5;
use strict;
use warnings;
use diagnostics;
my ( @chars, @uchars, @uints );
# win 2 UTF-8 transcoding:
# init {{
# char-s that I want to convert FROM
@chars = ( "š", "ć", "ę", "ł", "ó", "ń", "ś", "ż", "ź" );
# UTF double-bytes that I want to convert TO
@uchars = ( 0xC4, 0x85, 0xC4, 0x87, 0xC4, 0x99, 0xC5, 0x82, 0xC3, 0xB3, 0xC5,
0x84, 0xC5, 0x9B, 0xC5, 0xBC, 0xC5, 0xBA );
@uints = ();
for( my $i=0 ; $i<=$#chars ; $i++ ){
$uints[$i] = pack( "S", ($uchars[2*$i+1]<<8) | $uchars[2*$i] );
}
# }} init
# there's buffer to convert:
$xmlBuf = "Zażółć gęślš jaźń"; # this is like "Brown fox jumps over .*"
# let me ashame to do it like that (but it works!)
for( $i=0 ; $i<( $#uchars / 2 ) ; $i++ ){
$f = $chars[$i];
$t = $uints[$i];
$xmlBuf =~ s/$f/$t/g;
}
# now $xmlBuf is written with syswrite back to webserver...
</Perl>
### IMHO better UTF solution [B], but sysread fails? ###
Then I've commented all above solution and did:
<Perl>
require 5;
use strict;
use warnings;
use diagnostics;
# there's buffer to convert:
$xmlBuf = "Zażółć gęślš jaźń"; # this is like "Brown fox jumps over .*"
$xmlBuf = pack( "U*", map( ord($_), split( //, $xmlBuf ) ) );
# now $xmlBuf is written with syswrite back to webserver...
</Perl>
In both [A] and [B] solutions I've also written $xmlBuf to a file and both
files were IDENTICAL. But second solution [B] causes that:
1) not whole buffer is seen in web-browser (?) although syswrite reports that
the same amount of bytes is written to $socket and ...
2) after writing this request reply, my app should wait in 'sysread $socket
...' call for next request, but sysread returns 0 bytes read (don't blocks)!
And this really beates me!
Any ideas why solution [A] is working, and [B] is better - but not working?
Best regards,
---
Grzegorz Hayduk Akademia Górniczo-Hutnicza, EAIiE, KANiUP
P.S. ($OS, $PerlVer)=(Win98OSR2, v5.6.1);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]