我发现 PHP 中的 print_r 非常有用,但想知道 Perl 中是否有任何远程等效项?
最佳答案
注意@tchrist 推荐Data::Dump超过 Data::Dumper .我不知道它,但从它的外观来看,它似乎更容易使用并且产生更好的外观和更容易解释结果。
以上链接中显示的示例片段。
use Data::Dumper;
package Foo;
sub new {bless {'a' => 1, 'b' => sub { return "foo" }}, $_[0]};
package Fuz; # a weird REF-REF-SCALAR object
sub new {bless \($_ = \ 'fu\'z'), $_[0]};
package main;
$foo = Foo->new;
$fuz = Fuz->new;
$boo = [ 1, [], "abcd", \*foo,
{1 => 'a', 023 => 'b', 0x45 => 'c'},
\\"p\q\'r", $foo, $fuz];
########
# simple usage
########
$bar = eval(Dumper($boo));
print($@) if $@;
print Dumper($boo), Dumper($bar); # pretty print (no array indices)
$Data::Dumper::Terse = 1; # don't output names where feasible
$Data::Dumper::Indent = 0; # turn off all pretty print
print Dumper($boo), "\n";
$Data::Dumper::Indent = 1; # mild pretty print
print Dumper($boo);
$Data::Dumper::Indent = 3; # pretty print with array indices
print Dumper($boo);
$Data::Dumper::Useqq = 1; # print strings in double quotes
print Dumper($boo);
关于php - Perl 中与 PHP 的 print_r() 等价的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/229168/