我遇到了一个非常奇怪的UTF-8问题Net::Cassandra::Easy
(它建立在Net::Cassandra
上):写入Cassandra的UTF-8字符串在检索时出现乱码。Perl的Net :: Cassandra模块是否支持UTF-8?
下面的代码显示该问题:
use strict;
use utf8;
use warnings;
use Net::Cassandra::Easy;
binmode(STDOUT, ":utf8");
my $key = "some_key";
my $column = "some_column";
my $set_value = "\x{2603}"; # U+2603 is ☃ (SNOWMAN)
my $cassandra = Net::Cassandra::Easy->new(keyspace => "Keyspace1", server => "localhost");
$cassandra->connect();
$cassandra->mutate([$key], family => "Standard1", insertions => { $column => $set_value });
my $result = $cassandra->get([$key], family => "Standard1", standard => 1);
my $get_value = $result->{$key}->{"Standard1"}->{$column};
if ($set_value eq $get_value) {
# this is the path I want.
print "OK: $set_value == $get_value\n";
} else {
# this is the path I get.
print "ERR: $set_value != $get_value\n";
}
当运行上述$set_value eq $get_value
代码的计算结果为false
。我究竟做错了什么?
阅读后可能需要Encode :: decode_utf8。 (实际上,Encode :: encode_utf8用于写入。) – jrockway 2010-03-27 00:48:42