develooper Front page | perl.perl5.porters | Postings from June 2010

proposed addition to perlvar

Thread Next
Chas. Owens
June 8, 2010 09:23
proposed addition to perlvar
Message ID:
Due to some [confusion a new user had][1] finding the documentation
for what $# does in $#foo, I suggest we add a small note to perlvar to
point people in the right direction (patch inlined).

diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index ed90610..359dd62 100644
--- a/pod/perlvar.pod
+++ b/pod/perlvar.pod
@@ -879,6 +879,17 @@ as described below.

 Also see L<Error Indicators>.

+=item $#
+C<$#> is not a variable; it is a sigil like C<@> that can be prepended
+on the name of an array to get the index of the last item in that array.
+    my @a            = ("a", "b", "c");
+    my $last_index   = $#a;     # $last_index is 2
+    my $last_element = $a[$#a]; # $last_element is "c"
+Also see L<perldata>.
 =item $PROCESS_ID

 =item $PID

[1] :

Chas. Owens
The most important skill a programmer can have is the ability to read.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About