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

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

解决方法

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

Data::Dumper

上面链接显示的示例的一个片段。

  1. use Data::Dumper;
  2.  
  3. package Foo;
  4. sub new {bless {'a' => 1,'b' => sub { return "foo" }},$_[0]};
  5.  
  6. package Fuz; # a weird REF-REF-SCALAR object
  7. sub new {bless \($_ = \ 'fu\'z'),$_[0]};
  8.  
  9. package main;
  10. $foo = Foo->new;
  11. $fuz = Fuz->new;
  12. $boo = [ 1,[],"abcd",\*foo,{1 => 'a',023 => 'b',0x45 => 'c'},\\"p\q\'r",$foo,$fuz];
  13.  
  14. ########
  15. # simple usage
  16. ########
  17.  
  18. $bar = eval(Dumper($boo));
  19. print($@) if $@;
  20. print Dumper($boo),Dumper($bar); # pretty print (no array indices)
  21.  
  22. $Data::Dumper::Terse = 1; # don't output names where feasible
  23. $Data::Dumper::Indent = 0; # turn off all pretty print
  24. print Dumper($boo),"\n";
  25.  
  26. $Data::Dumper::Indent = 1; # mild pretty print
  27. print Dumper($boo);
  28.  
  29. $Data::Dumper::Indent = 3; # pretty print with array indices
  30. print Dumper($boo);
  31.  
  32. $Data::Dumper::Useqq = 1; # print strings in double quotes
  33. print Dumper($boo);

猜你在找的Perl相关文章