Confused by utf8/sysread/syswrite/DBD::Pg

Discussion in 'Perl Misc' started by A. Farber, Dec 29, 2009.

  1. A. Farber

    A. Farber Guest

    Hello,

    I have a multiplayer card game at http://preferans.de

    The Flash client sends and reads UTF8 data
    (prepended by 16-bit length to make
    Flash's readUTF() function happy)
    to the non-forking Perl server.

    Everything works fine until someone with a russian name joins.

    Then the Perl print displays his name as garbage
    (but not russian garbage ;-) and when I save
    that name into PostgreSQL (UTF8 database) it looks
    like this: http://preferans.de/viewforum.php?f=5

    So I've added a utf8::decode($name) for all user names.
    This has fixed print outputs and Postgres, but I've got

    Wide character in syswrite at /usr/libdata/perl5/i386-openbsd/5.10.0/
    IO/Handle.pm line 459.

    After reading
    http://london.pm.org/pipermail/london.pm/Week-of-Mon-20071210/011804.html

    I understand that I need to utf8::encode() the
    data I'm syswriting back to the Flash client.

    Here is my modified function:
    sub enqueue {
    my $child = shift;
    my $data = shift;
    my $fh = $child->{FH};
    my $response = $child->{RESPONSE};
    # flash.net.Socket.readUTF() expects 16-bit prefix in network
    order
    my $prefix = pack 'n', length $data;

    # append to the end of the outgoing queue
    push @{$response}, $prefix . utf8::encode($data);
    }

    Unfortunately I get the warning

    Use of uninitialized value $data in length at Child.pm line 234.
    Use of uninitialized value $data in concatenation (.) or string at
    Child.pm line 237.

    and everything stops working.

    Does anybody know what is going wrong here?
    My data is just an urlencoded data like "user0=Russian_name".

    Regards
    Alex

    PS: I'm using OpenBSD 4.5 with:

    p5-pgsql-1.9.0p0
    postgresql-client-8.3.6
    postgresql-server-8.3.6
    vim-7.2.77-no_x11

    and

    This is perl, v5.10.0 built for i386-openbsd

    And I connect from Windows using Putty and Vim
    who both are capable to display/edit UTF8.
     
    A. Farber, Dec 29, 2009
    #1
    1. Advertising

  2. A. Farber

    J. Gleixner Guest

    A. Farber wrote:
    [...]
    > Here is my modified function:
    > sub enqueue {
    > my $child = shift;
    > my $data = shift;
    > my $fh = $child->{FH};
    > my $response = $child->{RESPONSE};
    > # flash.net.Socket.readUTF() expects 16-bit prefix in network
    > order
    > my $prefix = pack 'n', length $data;
    >
    > # append to the end of the outgoing queue
    > push @{$response}, $prefix . utf8::encode($data);
    > }
    >
    > Unfortunately I get the warning
    >
    > Use of uninitialized value $data in length at Child.pm line 234.
    > Use of uninitialized value $data in concatenation (.) or string at
    > Child.pm line 237.
    >
    > and everything stops working.
    >
    > Does anybody know what is going wrong here?
    > My data is just an urlencoded data like "user0=Russian_name".


    You're sure? That warning is saying that $data is undefined.
     
    J. Gleixner, Dec 29, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Crook

    DBD::CSV questions and is there a DBD::XML?

    Andrew Crook, Sep 2, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    174
    Andrew Crook
    Sep 11, 2003
  2. Jim Cochrane
    Replies:
    0
    Views:
    120
    Jim Cochrane
    Aug 25, 2007
  3. sysread and syswrite analogy

    , Dec 4, 2008, in forum: Perl Misc
    Replies:
    7
    Views:
    218
  4. A. Farber

    utf8, length and syswrite are killing me

    A. Farber, Feb 17, 2010, in forum: Perl Misc
    Replies:
    2
    Views:
    242
    A. Farber
    Feb 18, 2010
  5. A. Farber
    Replies:
    2
    Views:
    145
    Uri Guttman
    May 14, 2010
Loading...

Share This Page