1
我有一個包含以下值的散列值。它有多個(2)每個鍵的值。Perl:在Perl中打印值,並在鍵值中使用特定的單詞
my %output = ("projectA" => [ "Compliant files excl rules: 456 - 76%
Noncompliant files excl rules 142 - 24% " ,
"Compliant files incl rules: 2910 - 84%
Noncompliant files incl rules: 572 - 16%" ],
"projectB" => [ "Compliant files excl rules: 345 - 72%
Noncompliant files excl rules 123 - 32% " ,
"Compliant files incl rules: 1234 - 98%
Noncompliant files incl rules: 232- 10%" ]);
所以,當我打印出來(電流輸出),看起來像下面
Project Excluding rules Including rules
----------------------------------------------------------------------------------------
ProjectA Compliant file excl rules: 456 -76% Compliant files incl rules: 2910 - 84%
Noncompliant files excl rules: 142-24% Noncompliant files incl rules:572 - 16%
ProjectB Compliant files excl rules: 345 - 72% Compliant files incl rules: 1234 - 98%
Noncompliant files excl rules: 123 - 32% Noncompliant files incl rules: 232- 10%
*所需的輸出*我怎樣才能打印出來沒有的話excl rules
和incl rules
。我不想爲每個項目重複他們,因爲我已經在標題中提到它。
Project Excluding rules Including rules
----------------------------------------------------------------------------------------
ProjectA Compliant files: 456 -76% Compliant files: 2910 - 84%
Noncompliant files: 142-24% Noncompliant files:572 - 16%
ProjectB Compliant files: 345 - 72% Compliant files : 1234 - 98%
Noncompliant files:123 - 32% Noncompliant files: 232- 10%
我使用打印它們目前的代碼是:
my $key;
foreach $key (sort keys %output) {
$html .= "<tr><td>$key</td>";
$html .= "<td>$_</td>" for @{ $output{$key} };
$html .= " </tr>";
}
它沒有工作。列2和列3中的內容並未全部打印。 – Jill448 2014-09-25 14:55:55
@ sravs448:看我的編輯。 – Toto 2014-09-25 15:07:06
非常感謝。它工作 – Jill448 2014-09-25 15:24:28