CPAN::Forum
threads - utf8 problems in relation with Thread::Queue::Duplex
| Posted on Mon Mar 31 20:39:22 2008 by geronime |
| utf8 problems in relation with Thread::Queue::Duplex |
|
Hello,
I am no advanced user to PERL and I have following code:
use utf8;
use open ':utf8', ':std';
use threads;
use Thread::Queue::Duplex;
my $queue = Thread::Queue::Duplex -> new;
sub thrd { # thread function
use utf8;
my $tid = threads -> self -> tid();
my $seq = 0;
$SIG{'INT'} = sub { print "thrd[$tid]: exiting on signal.\n"; threads -> exit; };
$queue -> listen;
my $id; my %params;
while ( 1 ) {
$req = $queue -> dequeue_until ( 2 );
next unless defined $req; # no signal and no data read, restart cycle
($id, %params) = @$req;
print "thrd[$tid]: request #$id: '" . join ( "','", %params ) . "'\n";
$queue -> respond ( $id, $params{'keyword'} );
}
}
$thrd = threads -> create ( \&thrd );
%hash = ( 'keyword' => "í" ); # please convert into character, ord of this char is 237
%hash2= ( 'keyword' => "&#xu011B;" ); # please convert into character, ord is 283
print "Main: data: '" . $hash{'keyword'} . "'\n";
print "Main: data2: '" . $hash2{'keyword'} . "'\n";
$id = $queue -> enqueue ( %hash );
print "Main: request done, id=$id\n";
$response = $queue -> dequeue_response ( $id );
print "Main: response for request #$id: '" . join ( "','", @$response ) . "'\n";
$id = $queue -> enqueue ( %hash2 );
print "Main: request done, id=$id\n";
$response = $queue -> dequeue_response ( $id );
print "Main: response for request #$id: '" . join ( "','", @$response ) . "'\n";
$thrd -> kill ( 'SIGINT' ) -> join; # end the thread
print "Main: Exiting.\n";
Output is:
Main: data: '<correct character>'
Main: data2: '<correct character>'
Main: request done, id=1
thrd[1]: request #1: 'keyword','<incorrect character, probably in latin1 charset>'
Main: response for request #1: '<correct character>'
Main: request done, id=2
Wide character in print at pokus-duplex.pl line 19.
thrd[1]: request #2: 'keyword','<correct character>'
Main: response for request #2: '<correct character>'
thrd[1]: exiting on signal.
Main: Exiting.
Perl version and OS:
$ perl -v
This is perl, v5.8.8 built for i86pc-solaris-thread-multi
Copyright 1987-2006, Larry Wall
...
The script is written in utf8. The strings are wrong encoded for strings containing only certain utf8 characters, but the response is correct again. I was not able to post here the characters as are in the code/output. I was experimenting quite lot, but without any success. Ask whatever more information you need. Can you please help? TYVM in advance BR, Jiri |
| Direct Responses: 7544 | Write a response |
(0)
]