suppose i have an array:
@array = {
'A' => "",
'B' => 0,
'C' => 0,
'D' => 0,
};
i can add an element by:
$count = 0;
$array[$count]->{A} = "abcd";
$array[$count]->{B} = 789;
$array[$count]->{C} = 456;
$array[$count]->{D} = 123;
and another element,
$count++;
$array[$count]->{A} = "efgh";
$array[$count]->{B} = 111;
$array[$count]->{C} = 222;
$array[$count]->{D} = 333;
how can i add elements to @array using push?
That first structure you have is a
hash reference, not anarray. You cannot add values to aHashviapush.pushwill only operate on anarray. If you wish to add a value to ahash referenceyou will need to either use->notation or dereference.If you have an
array referenceinside of ahash referenceyou can access it in the same manner as above.As for creating an array you use
(and)like soAnother option is to use the
qw()shortcut like soAdditionally you can create an array by reference using
[and]Finally to push a value to an array you use
pushThough, push being a list context function can be written sans parens.