我一直致力于支持perl cgi程序,而且我的perl体验功能很少。
有一个方法需要$ args,我想知道$ args是什么。
以下是我首先尝试的方式:
print( "=== DEBUG 2 === Creating session with the following args: ", $args, "\n" );
打印哪些:
=== DEBUG 2 === Creating session with the following args: HASH(0x2b462cc7c880)
所以这是哈希啊,好吧。有点谷歌搜索,我试试这个:
my $counter = 1;
print( "=== DEBUG === Creating session with the following args: \n" );
foreach (keys $args) {
print "$_ : $args{$_}\n";
}
这会导致整个程序崩溃而没有任何有用的错误消息。我猜$ args不能用于密钥。
如何将$ args的内容转储到打印?
注意:尝试使用数据转储器也会导致整个程序崩溃而不会显示错误消息。
答案 0 :(得分:3)
$args
不是哈希,它是哈希引用。您需要首先取消引用它以访问底层哈希。
foreach (keys %$args) {
# You could use this:
# print "$_: ${$args}{$_}\n";
# but the -> operator is a little more readable.
print "$_: $args->{$_}\n";
}
each
运算符允许您迭代哈希,同时为每个键和值提供名称:
while (my ($key, $value) = each %$args) {
print "$key: $value\n";
}
答案 1 :(得分:1)
尝试这种方式:
foreach (keys %{$args}) {
print "$_ : ".$args->{$_}."\n";
}
可能$ args不是哈希,而是对哈希的引用。
答案 2 :(得分:1)
$ args似乎是一个哈希引用。
打印整个哈希:
print %$args;
按键打印键:
print "$_ $args->{$_}\n" foreach (keys %$args);