我发现print_r在PHP非常有用,但想知道是否有任何远程等同于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);
原文地址:https://www.jb51.cc/Perl/173241.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。