Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
perl格式和utf数据存在问题_Perl_Format - Fatal编程技术网

perl格式和utf数据存在问题

perl格式和utf数据存在问题,perl,format,Perl,Format,我使用perl格式将行打印到文件中 即 我在网上找到了很多不同的解决方案,但都没有成功 binmode STDOUT, ":utf8"; use open qw( :std :encoding(UTF-8) ); use Encode; use Encode 'is_utf8'; $first_name = decode_utf8($first_name); 我也试过了 use Encode 'from_to'; from_to($write_name, "utf-8", "iso-88

我使用perl格式将行打印到文件中

我在网上找到了很多不同的解决方案,但都没有成功

binmode STDOUT, ":utf8";

use open qw( :std :encoding(UTF-8) );

use Encode;
use Encode 'is_utf8';

$first_name = decode_utf8($first_name);
我也试过了

use Encode 'from_to';
from_to($write_name, "utf-8", "iso-8859-1");

open my $fh, ">:utf8", $filename
    or die "could not open $filename: $!\n";

除了用?s替换utf字符外,哪种方式有效

找到的一种解决方案是,将字符串打印到文件中,然后将字符串读回文件并再次存储在变量中

请注意,该格式适用于windows环境。这个问题只发生在unix中


我希望您有一个更好的解决方案。

由于格式的API过于疯狂,因此不鼓励使用格式,您可能希望改用Template::Toolkit。

您发布了一些可能不适用的内容,我建议删除其中的一些杂乱内容。然而,我实际上更想看到的是如何将数据放入数据库,以及如何将数据取出,因为这可能是问题所在。UTF-8只是一个字节字符串,其中可以有多字节字符。多字节部分(前导字符或后面但在多字节字符内的字符)的编码肯定有问题。Oracle返回的数据中的UTF-8标志是打开的,还是关闭的?是否显式地对输出流进行binmode?使用标准DBI检索数据$dbh=DBI->connectdbi:Oracle:$ODS\u DB、$ODS\u ADPCOS\u ID、$ODS\u ADPCOS\u PSWD或connect上的die;使用标准perl-DBI$dbh=DBI->connectdbi:Oracle检索数据:$ODS\u DB、$ODS\u ADPCOS\u ID、$ODS\u ADPCOS\u PSWD或connect上的die die$sql=选择写入名称。来自个人。其中person.id=。 '. $学生号;$sth=$dbh->prepare$sql或die print STDERR无法准备语句:$sql\n数据库错误:$DBI::errstr$sth->execute或die print STDERR无法执行:$sth\n数据库错误:$DBI::errstr;$write\u name=$sth->fetchrow\u数组;写入文件openREPORT1、>>$report\u file或die print STDERR无法打开输出文件-$report\u file-$\N选择REPORT1$每个页面的格式行=$my\u LINES\u PAGE$格式\页码\编号=0$格式\行\左=0;循环writeREPORT1;将格式化输出写入文件end loop REPORT1的格式如上所述。
009999990  000000133  Anderson, Charlie                                        30           25           25      83.3         83.3

-----------------------------------------------------------------------------------------------------------------------------

009999951  000000132  Smith, Josée                                            29           21           21      70.0         70.0

-----------------------------------------------------------------------------------------------------------------------------

009999934  000000131  Quiring, Randy                                           30           12           12      40.0    
binmode STDOUT, ":utf8";

use open qw( :std :encoding(UTF-8) );

use Encode;
use Encode 'is_utf8';

$first_name = decode_utf8($first_name);
use Encode 'from_to';
from_to($write_name, "utf-8", "iso-8859-1");

open my $fh, ">:utf8", $filename
    or die "could not open $filename: $!\n";
from_to($write_name, "utf-8", "WINDOWS-1252");