The following is a reference to an array of hashes. Given such an array reference, I would like to remove the last element always. Will pop work, as hashes don't maintain any order?
$arrayref = [
{
'F1' => V1,
'F2' => V2,
},
{
'F1' => V3,开发者_开发问答
'F2' => V4,
},
.
.
.
];
pop @$arrayref
or
splice(@$arrayref, -1)
or
--$#$arrayref;
For some easy to remember rules to help you use references, see http://perlmonks.org/?node=References+quick+reference.
It works. Try:
pop @{$arrayref};
Hashes don't maintain any order. But you are working with an array of objects (hashes). Arrays maintain order.
精彩评论