我有一个脚本将HL7消息发送给Mirth。这是程序:
use Net::HL7;
use Net::HL7::Connection;
use open ( ":encoding(UTF-8)", ":std" );
binmode(STDOUT, ":utf8");
my $conn = new Net::HL7::Connection('127.0.0.1', 7010);
my $msg = getHl7Message(); # Too many things happening in getHl7Message()
print($msg) # All characters are correct in $msg when printed
my $hl7msg = new Net::HL7::Message($msg);
print($hl7msg->toString(1)) #All characters are correct
my $response = $conn->send($hl7msg); #sent to Mirth
现在,当我检查欢笑时,ASCII集之外的所有字符都会失真。
我该怎么办? Net :: HL7 :: Connection在内部使用IO :: Socket。
我也收到这个警告:
Wide character in print at /usr/local/share/perl5/Net/HL7/Connection.pm line 143.
我尝试用-CS执行但仍然无法获得。
一些信息:
[user@server gs]$ lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: OracleServer
Description: Oracle Linux Server release 6.6
Release: 6.6
Codename: n/a
/ etc / environment和/ etc / default / locale为空。我添加了这两行
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
结果:
[user@server gs]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
答案 0 :(得分:0)
您将UTF-8编码层放在STDOUT上,但是您不能将该层放在HL7频道上(无论是什么),并且您不会以UTF-8编码您的消息。这就是您看到Wide print ...
警告的原因。将UTF-8编码的字符串写入HL7连接。
my $msg = getHl7Message();
# $msg is not encoded.
# map{chr}split//,$msg should produce some values larger than 255
print($msg);
# this is ok because the :utf8 layer was applied to STDOUT.
# Behind the scenes, the string $msg is encoded before it is output
# to the terminal.
my $msgutf8 = Encode::encode("UTF-8", $msg);
# Now $msgutf8 is a UTF-8 encoded "octet string".
# map{chr}split//,$msgutf8 should only produce vals between 0 and 255,
# and is safe to transmit
my $hl7msg = new Net::HL7::Message($msgutf8);