什么是Perl的等价于PHP的print_r()?

前端之家收集整理的这篇文章主要介绍了什么是Perl的等价于PHP的print_r()?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我发现print_r在PHP非常有用,但想知道是否有任何远程等同于Perl?

解决方法

注意@tchrist建议 Data::Dump超过 Data::Dumper.我不知道它,但从它的外观,似乎它更容易使用,更好的看起来更容易解释的结果。

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);

猜你在找的Perl相关文章