Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I push a value onto a Perl hash of arrays?

Tags:

arrays

hash

perl

%TEST ; 

... 
for  {
   sub atest
   }
 sub atest {
 ...
    push $TEST { TEST1 }[0] = "some value " 
}

How do I push values into a hash of arrays without knowing anything about index?

How do I achieve this?

like image 527
Tree Avatar asked Sep 23 '10 14:09

Tree


1 Answers

This will add value to the end of array stored in hash by "TEST1" key.

push( @{ $TEST { TEST1 } }, "some value "); 

I've used @{...} to dereference array reference. Perl creates inner array reference automatically then needed.

like image 186
Ivan Nevostruev Avatar answered Sep 21 '22 19:09

Ivan Nevostruev