首页 > 解决方案 > 如何将 perl assc 数组指向简单数组并推送新值?

问题描述

这是概念:

%aa = (
  'allphotos' => {}
);

$newkey = 'photogroupone';
$newphotoone = 'dogs at play';
$newphototwo = 'cats at play';

push $aa{'allphotos'}{$newkey}, $newphotoone;
push $aa{'allphotos'}{$newkey}, $newphototwo;

Perl 5.24

他们希望发布更多文字。有什么好说的。

标签: arraysperl

解决方案


关。第一个参数必须是一个数组。

push @{ $aa{'allphotos'}{$newkey} }, $newphotoone;
push @{ $aa{'allphotos'}{$newkey} }, $newphototwo;

要不就

push @{ $aa{'allphotos'}{$newkey} }, $newphotoone, $newphototwo;

推荐阅读