in reply to strange syntax

That funny syntax represents the index of the last element of an array starting from 0, eg:

#!/usr/bin/perl use warnings; use strict; my @a = qw(0 1 2 3 4 5); print "$#a\n\n"; for my $i (0 .. $#a){ print "$i\n"; } print "elem 5: $a[$#a]\n"; # same as $a[-1] or $a[5]

Output:

5 0 1 2 3 4 5 elem 5: 5

-stevieb

Replies are listed 'Best First'.
Re^2: strange syntax
by MidLifeXis (Monsignor) on Jun 17, 2015 at 12:32 UTC

    Slight nit, even if it is not recommended use (deprecated since 5.12.0):

    That funny syntax represents the index of the last element of an array starting from 0$[
    Today 0 is accurate, but who knows the original context of the provided code.

    --MidLifeXis