开发者

How to pop the last element from an array of hashes?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜