Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: same utf8 string is different in console and in browser (Sybase)

by choroba (Cardinal)
on Aug 19, 2017 at 17:46 UTC ( [id://1197665]=note: print w/replies, xml ) Need Help??


in reply to [SOLVED] same utf8 string is different in console and in browser (Sybase)

This can happen when one of the strings is utf-8, while the other one is bytes.

Compare:

#! /usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use utf8;
 
my @strings = ('школы',
               "\xd1\x88\xd0\xba\xd0\xbe\xd0\xbb\xd1\x8b");
 
say for @strings;
 
binmode STDOUT, ':encoding(UTF-8)';
say for @strings;

The first two lines are the same:

школы
школы

but once the output knows it expects UTF-8 (the third and fourth line), the output is different:

школы
ΡΠΊΠΎΠ»Ρ

You probably didn't tell Sybase your strings are UTF-8.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
  • Comment on Re: same utf8 string is different in console and in browser (Sybase)
  • Download Code

Replies are listed 'Best First'.
Re^2: same utf8 string is different in console and in browser (Sybase)
by alexander_lunev (Pilgrim) on Aug 19, 2017 at 18:22 UTC

    But you were right! I've changed way to connect to MSSQL, and when i connect through freetds.conf with DBI:Sybase:server=server_name;database=database_name", strings output to browser as they should! I have tried with syb_enable_utf8 => 1, tried to put charset=utf8 in DSN, with no changes. Now i add server to freetds.conf and add client charset = UTF-8 and it works.

    Though i still don't get it, why the very bytes of $str turns different only because of script called by CGI...

      So, some hidden thing there. Different environment settings for command line and web server?

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^2: same utf8 string is different in console and in browser (Sybase)
by alexander_lunev (Pilgrim) on Aug 19, 2017 at 18:05 UTC
    I think it's not the case, because if i add binmode STDOUT, ':encoding(UTF-8)', output in console is the same for Pg and Sybase:
    Sybase Ρ�ΠΊΠΎΠ»Ρ�#Π�Π°Ρ�Ρ�Π° > 0xD1 + 0x88 0xD0 0xBA 0xD0 0xBE 0xD0 0xBB 0xD1 0x8B 0x23 0xD0 0x9A 0xD0 0xB +0 0xD1 0x81 0xD1 0x81 0xD0 0xB0 Pg Ρ�ΠΊΠΎΠ»Ρ�#Π�Π°Ρ�Ρ�Π° > 0xD1 0x8 +8 0xD0 0xBA 0xD0 0xBE 0xD0 0xBB 0xD1 0x8B 0x23 0xD0 0x9A 0xD0 0xB0 0x +D1 0x81 0xD1 0x81 0xD0 0xB0

    But in browser again all different:

    Sybase ?????#????? > 0x3F 0x3F 0x3F 0x3F 0x3F 0x23 0x3F 0x3F 0x3F 0x3F + 0x3F Pg ΡˆΠΊΠΎΠ»Ρ‹#ΠšΠ°ΡΡΠ° > 0xD1 0x88 0xD0 0xBA 0xD0 0xB +E 0xD0 0xBB 0xD1 0x8B 0x23 0xD0 0x9A 0xD0 0xB0 0xD1 0x81 0xD1 0x81 0x +D0 0xB0

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1197665]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found