Perl How to get the index of last element of array reference?

后端 未结 4 1742
情歌与酒
情歌与酒 2021-02-06 22:52

If we have array then we can do following:

my @arr = qw(Field3 Field1 Field2 Field5 Field4);
my $last_arr_index=$#arr;

How do we do this for ar

4条回答
  •  天涯浪人
    2021-02-06 23:34

    my $arr_ref = [qw(Field3 Field1 Field2 Field5 Field4)];
    
    my $last_aref_index = $$arr_ref[$#{$arr_ref}];
    print "last element is: $last_aref_index\n";
    

提交回复
热议问题