Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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中将变量打印到文件中?_Perl_File_Variables_Printing - Fatal编程技术网

如何在Perl中将变量打印到文件中?

如何在Perl中将变量打印到文件中?,perl,file,variables,printing,Perl,File,Variables,Printing,我正在使用以下代码尝试将变量打印到文件中 my $filename = "test/test.csv"; open FILE, "<$filename"; my $xml = get "http://someurl.com"; print $xml; print FILE $xml; close FILE; my$filename=“test/test.csv”; 打开文件,“该打开一个文件进行写入(或使用>进行追加) 还值得添加一些错误处理: use strict; use warni

我正在使用以下代码尝试将变量打印到文件中

my $filename = "test/test.csv";
open FILE, "<$filename";
my $xml = get "http://someurl.com";
print $xml;
print FILE $xml;
close FILE;
my$filename=“test/test.csv”;
打开文件,“该
打开一个文件进行写入(或使用
>
进行追加)

还值得添加一些错误处理:

use strict;
use warnings;
use LWP::Simple;

my $filename = "test/test.csv";
open my $fh, ">", $filename or die("Could not open file. $!");
my $xml = get "http://example.com";
print $xml;
print $fh $xml;
close $fh;

+1对于三参数版本的
打开
,使用词法文件句柄和错误检查。