什么是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);

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...