简体   繁体   English

在Perl中,如何将Dumper的输出写入文件?

[英]In Perl, how can I write the output of Dumper to a file?

如何让Data::Dumper将转储写入文件?

Don't forget that you can specify the file handle to print to as in 不要忘记您可以指定要print的文件句柄

print $LOG Dumper( \%some_complex_hash );

or use File::Slurp : 或使用File :: Slurp

write_file 'mydump.log', Dumper( \%some_complex_hash );

Further thoughts: You might want to get into the habit of using: 进一步的想法:你可能想养成使用的习惯:

warn Dumper( \%some_complex_hash );

and redirecting standard error to a file when you invoke your script (how you do this depends on the shell). 并在调用脚本时将标准错误重定向到文件(如何执行此操作取决于shell)。 For example: 例如:

 C:\Temp> sdf.pl 2>dump

使用打印

print FILE Data::Dumper->Dump($object);

The question is a bit unclear, but are you looking for something like this? 问题有点不清楚,但你在找这样的东西吗?

open my $FH, '>', 'outfile';
print $FH Dumper(\%data);
close $FH;

You can restore the data later by using eval . 您可以稍后使用eval恢复数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM