0

Data::Dumper - Dumper($cat_response->result->{'categories'}) を通じて表示される応答があります

$VAR1 = { 'literature' => '1120', 'law' => '1153', 'arts and crafts' => '1132', 'children' => '1141', 'hobbies' => '1133', 'economy' => '1166', 'jobs' => '1140', 'media' => '1144', 'music' => '1147', 'animals' => '1170', 'business' => '1119', 'diet' => '1122', 'travel reviews' => '1154', 'jewelry' => '1157', 'movies' => '1146', 'television' => '1125', 'politics' => '1168', 'internet' => '1139', 'history' => '1129', 'recipes' => '1156', 'press releases' => '1151', 'presents' => '1128', 'marketing' => '1143', 'translations' => '1162', 'fashion' => '1145', 'technology' => '1163', 'real estate' => '1138', 'computer' => '1173', 'automobile' => '1116', 'finances' => '1126', 'weddings' => '1134', 'games' => '1127', 'esoterism' => '1124', 'horoscopes' => '1135', 'shopping' => '1123', 'humor' => '1137', 'miscellaneous' => '1159', 'science' => '1167', 'programming' => '1152', 'languages' => '1161', 'beauty' => '1117', 'sports' => '1160', 'hotels' => '1136', 'plants' => '1149', 'education' => '1118', 'traveling' => '1155', 'health' => '1130', 'telecommunication' => '1164', 'environment' => '1171', 'software' => '1158', 'sweepstakes' => '1131', 'logistics' => '1142', 'home and family' => '1169', 'news' => '1148' };

それにアクセスするには、次を使用します。

my %categories = $cat_response->result->{'categories'};
foreach my $cat (keys (%categories)) {
    <option value="<% $categories{'$cat'} %>"><% $cat %></option>
}

ただし、Dumper($cat) の値は次のとおりです。 $VAR1 = 'HASH(0x7fe972641560)';

私は何か見落としてますか?

4

1 に答える 1

2

あなたは1つ欠けuse strict; use warnings;ています。(まあ、それか、Perl があなたの問題について教えてくれたことを私たちに言い忘れたかのどちらかです。)

$cat_response->result->{'categories'}ハッシュへの参照が含まれています。それをハッシュに割り当てる意味はありません。

my $categories = $cat_response->result->{'categories'};
foreach my $cat (keys (%$categories)) {
    <option value="<% $categories->{'$cat'} %>"><% $cat %></option>
}
于 2012-10-17T20:46:15.360 に答える