我遇到多维数组的问题。然后,我在 Perl第4版一书中尝试了一个示例,第379页,这也失败了!为什么呢?
#!/usr/bin/perl
use strict;
use warnings;
# example in manual page 379
# input from file containing: husband=fred pal=barney wife=wilma pet=dino
while ( <> ) {
next unless s/^(.*?):\s*//;
my $who = $1;
for my $field ( split ) {
(my $key, my $value) = split /=/, $field;
my $HoH{$who}{$key} = $value;
}
}
`
答案 0 :(得分:2)
说明性示例的有用技巧 - 您可以在文件末尾的__DATA__
行,并使用它。
无论如何,当我运行你的代码时,我得到:
Global symbol "$key" requires explicit package name (did you forget to declare "my $key"?)
Global symbol "$value" requires explicit package name (did you forget to declare "my $value"?
您也宣布%HoH
严重 - 您不应该使用该表单,而是:
my %HoH;
还正则表达式 - 会跳过您的输入文字,因为它正在查找:
,而您的输入并不包含任何内容。我会假设它应该以{{1}}为前缀。
所以简化并给你一些有用的东西:
flintstone:
这输出转储的HoH:
#! usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %HoH;
while (<DATA>) {
next unless s/^(.*?):\s*//;
my $who = $1;
for my $field (split) {
my ( $key, $value ) = split /=/, $field;
$HoH{$who}{$key} = $value;
}
}
print Dumper \%HoH;
__DATA__
flintstone: husband=fred pal=barney wife=wilma pet=dino
答案 1 :(得分:1)
您的代码包含一些语法错误,输入文本错误(没有if (isset($_POST['your_submit'] )) {
echo "<yourdialog>";
echo "<form action="system/web/push.php">";
echo "content";
echo "<submit yes>";
echo "</form>";
echo "</yourdialog>";
}
试试这个:
: