Take the 2-minute tour ×

I can't seem to find explicit documentation for $# in perldoc.

Yes, I know what it is, and I can see implicit references in places like perllol and perldsc, but I can't seem to find anything standalone.

What's really surprising is that it doesn't have it's own section in perlvar.

Does such documentation exist? If so, where?

share|improve this question

2 Answers 2

up vote 14 down vote accepted

$# is not a special variable, it is a sigil like $, @, %, &, and *. Since it is just part of how arrays work, you will find it documented in perldoc perldata with the rest of the documentation on how variables work.

$#foo is just a way of asking @foo what its last index is. There is no separate symbol table entry for it (like there is for $foo, %foo, &foo, and the filehandle foo).

share|improve this answer
Hmm, I'd have thought it would be 'special'. Oh, does $# have a name? 'Last-array-element-subscript' is the best I can come up with atm. –  Zaid Jun 8 '10 at 12:10
@Zaid I normally pronounce $#foo as "last index of foo". –  Chas. Owens Jun 8 '10 at 12:39
$# maybe should be in perlvar. It isn't a variable, but imagine a newbie who wants to understand what $#blah does. Where is s/he going to look? Knowing to look in perldata requires knowing that $# is related to Perl data types. How do you find the answer if you don't know the answer? Search? Searching for things like $# and $/ doesn't work well as most search systems strip nonword characters from their indexes. Perl's docs are extensive and well written, but they are hard for a newbie to use. I don't have a good suggestion for how to fix this, but I want to call attention to it. –  daotoad Jun 8 '10 at 15:14
@daotoad, so you think we should add =item $#\n\nC<$#> is not actually a variable. It is a sigil that can be prepended to an array's name to get the last index in that array (e.g. $#foo is the last index in @foo). For more information see L<perldata>.\n\n to perlvar.pod? –  Chas. Owens Jun 8 '10 at 15:50
A patch has been suggest to p5p: nntp.perl.org/group/perl.perl5.porters/2010/06/msg160812.html –  Chas. Owens Jun 8 '10 at 18:57

Actually, $# used to be a builtin variable:


The output format for printed numbers. This variable is a half-hearted attempt to emulate awk's OFMT variable. There are times, however, when awk and perl have differing notions of what is in fact numeric. Also, the initial value is %.20g rather than %.6g, so you need to set $# explicitly to get awk's value. (Mnemonic: # is the number sign.)

$# was removed in 5.10.0.


C:\> perl -e "print $#"
$# is no longer supported at -e line 1.


share|improve this answer
I thought I remembered $# having a life of its own, but it wasn't there when I went search the POD. Looks like it got removed in Perl 5.10.0. –  Chas. Owens Jun 8 '10 at 19:04
@Chas. According to search.cpan.org/~andyd/perl5.003_07/pod/perlvar.pod $# was deprecated in Perl 5. It was removed with 5.10.1. See search.cpan.org/~dapm/perl-5.10.1/pod/… –  Sinan Ünür Jun 8 '10 at 19:35
Interesting, it was removed from perlvar in Perl 5.10.0 (perldoc.perl.org/5.10.0/perlvar.html) it used to come right before $FORMAT_PAGE_NUMBER. –  Chas. Owens Jun 8 '10 at 20:21
It looks like they just reiterated the removal in Perl 5.10.1, because it is listed in Perl 5.10.0's perldelta: search.cpan.org/~rgarcia/perl-5.10.0/pod/…*_and_$#_‌​variables_have_been_removed –  Chas. Owens Jun 8 '10 at 20:27
Interesting history behind $#... seems that my gut instinct to check perlvar was not completely unfounded after all. –  Zaid Jun 8 '10 at 20:37

Your Answer


