You are viewing the version of this documentation from Perl 5.12.2. View the latest version
$#

$# used to be a variable that could be used to format printed numbers. After a deprecation cycle, its magic was removed in Perl 5.10 and using it now triggers a warning: $# is no longer supported.

$# is also used as sigil, which, when prepended on the name of an array, gives the index of the last element in that array.

my @array        = ("a", "b", "c");
my $last_index   = $#array;   # $last_index is 2

for my $i (0 .. $#array) {
    print "The value of index $i is $array[$i]\n";
}

Also see perldata.