【发布时间】:2015-01-17 11:29:02
【问题描述】:
我的哈希表是这样的:
$VAR1 = \{
'Good night , she said softly .' => {
'tokens_en' => [
'Good',
'night',
',',
'she',
'said',
'softly',
'.'
],
'tokens_fr' => [
'word_fr_1',
'word_fr_2',
'word_fr_1'
],
'score' => '0.270968',
'sentence' => 'word_fr_1 word_fr_2 word_fr_3 .'
}
};
现在我需要将信息添加到哈希表中与“tokens_en”对应的值,如下所示:
$VAR1 = \{
'Good night , she said softly .' => {
'tokens_en' => [
'Good' => [a,b,c],
'night',
',',
'she' => [d,e,f],
'said' => [g,h,i],
'softly' => [k,l,m],
'.'
],
我怎么能做到这一点,我已经尝试过这段代码但不起作用:
$hash->{sentence1}->{tokens_en}{\@tokens_en} = \@tokens_test;
具有 [a,b,c] 和 [d,e,f] 等值的表在其他步骤中创建。
【问题讨论】:
-
为什么是
$hash->{sentence1}->{tokens_en}{\@tokens_en} = \@tokens_test;?$hash->{sentence1}->{tokens_en} = \@tokens_test;怎么样? -
你用什么命令来转储哈希?
$VAR1 = \{ ... };很奇怪 -
[ 'Good', [ 'word1', 'word2', ], 'night', ',', ... ]?您想要的格式毫无意义。 -
最后,你想要达到的目标还不清楚。
-
对不起,我已经澄清了最初的问题。事实上,新信息 [a,b,c] 与 [word1,word2,word3] 完全不同。我想将一个字符串数组与每个 token_en 字符串相关联。我希望它更清楚。