Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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会打印%x";从一个文件读取并写入另一个文件时作为数值?_Perl_Printf - Fatal编程技术网

为什么perl会打印%x";从一个文件读取并写入另一个文件时作为数值?

为什么perl会打印%x";从一个文件读取并写入另一个文件时作为数值?,perl,printf,Perl,Printf,我在文件1中有此文本: printf ("integer value is %x \n", a); 我想从文件1中读取数据并写入文件2中。 当我到达这一行时,文件2如下所示: printf ("integer value is 0 \n", a); 为什么会这样?我怎样才能避免这种情况 以下是我的Perl代码的外观: while ($line = <$in_fh>) { printf $out_fh $line; } while($line=){ printf$out\

我在文件1中有此文本:

printf ("integer value is %x \n", a);
我想从文件1中读取数据并写入文件2中。 当我到达这一行时,文件2如下所示:

printf ("integer value is 0 \n", a);
为什么会这样?我怎样才能避免这种情况

以下是我的Perl代码的外观:

while ($line = <$in_fh>) {
    printf $out_fh $line;
}
while($line=){
printf$out\u fh$行;
}
这里,$in\u fh和$out\u fh是输入和输出文件句柄。

因为这就是它的作用。你想要的

因为这就是我所做的。你想要的


因为
printf
$line
解释为一个格式字符串,并找到看起来像令牌的
%x
。改用
print

因为
printf
$line
解释为格式字符串,并查找类似于标记的
%x
。使用
打印

while ($line = <$in_fh>) {
    print $out_fh $line;
}
while ($line = <$in_fh>) {
    printf $out_fh "%s", $line;
}