php - Perl 中与 PHP 的 print_r() 等价的是什么?

标签 php perl debugging

我发现 PHP 中的 print_r 非常有用,但想知道 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);

关于php - Perl 中与 PHP 的 print_r() 等价的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/229168/

相关文章:

perl - 在perl中加密/解密

debugging - 断言具有副作用的函数的返回值的 Rust 方法是什么?

python - 如何在 python 中恢复旧的回溯? (例如倒数第二个)

php - 对用连字符分隔的表 ID 进行排序 (PHP/MySQL)

php - 比较来自 MySql 和 Datepicker 的日期

php - 如何在同一个 php 中将两个 Select 查询的输出合并到一个 JsonObject 中?

windows - 如何在 Windows 上同时使用 ActiveState 和 Strawberry perl

windows - Windows 上的 perl : Can't do inplace edit on file: File exists

debugging - GameMaker Studio - 不存在的表面

php - 使用 PHP 的持久性 MySQL 查询结果