I am not sure what to call the following data structure: Hash or Array.
I am trying to add a 3rd element to it. Can someone please guide me. Some explanation would be much appreciated as I am new to perl and to this forum as well.
Existing structure:
my $var= [
bless( {
'name' => 'Name1',
'groupid' => '2',
'description' => 'Desc2'
}, 'my_type' ),
bless( {
'name' => 'Name2',
'groupid' => '4',
'description' => 'Desc3'
}, 'my_type' ),
];
I want to add the following into it:
bless( {
'name' => 'Name3',
'groupid' => '9',
'description' => 'Desc4'
}, 'my_type' ),
Thank you for your time and help!
your
$varis an “arrayref”.With array, we can
pushelements at the end:To use an arrayref as an array, we have to dereference it:
In these simple cases the dereferencing can be shortened, so we could have written
In your case this would be