Counting array elements in Perl

前端 未结 6 1683
逝去的感伤
逝去的感伤 2021-02-02 09:29

How do I get the total items in an array, NOT the last id?

None of two ways I found to do this works:

my @a;
# Add some elements (no consecutive ids)
$a[         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-02 10:05

    Maybe you want a hash instead (or in addition). Arrays are an ordered set of elements; if you create $foo[23], you implicitly create $foo[0] through $foo[22].

提交回复
热议问题