0

This is the concept:

%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

They want additional text to post. What's to say.

serenesat
  • 4,611
  • 10
  • 37
  • 53
user116032
  • 321
  • 2
  • 15
  • 3
    Let autovivication help you out. `my %aa; push @{ $aa{allphotos}{$newkey} }, $newphotoone, $newphototwo;` – GMB Jan 21 '19 at 00:33
  • Thanks. But I'm getting this: Experimental push on scalar is now forbidden at ... – user116032 Jan 21 '19 at 00:46
  • lol... There's so many delimiters here I don't know what I did. I just added (or so I think I just added, push() parens. Now it works. Thanks https://stackoverflow.com/questions/3779213/how-do-i-push-a-value-onto-a-perl-hash-of-arrays – user116032 Jan 21 '19 at 01:05
  • 3
    Re "*But I'm getting this*", From your code, yes, but not from GMB's. The parens aren't needed, but `@{ ... }` is. – ikegami Jan 21 '19 at 03:07

1 Answers1

3

Close. The first argument has to be an array.

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

or just

push @{ $aa{'allphotos'}{$newkey} }, $newphotoone, $newphototwo;
ikegami
  • 367,544
  • 15
  • 269
  • 518