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

proposed addition to perlvar

Thread Next
From:
Chas. Owens
Date:
June 8, 2010 09:23
Subject:
proposed addition to perlvar
Message ID:
AANLkTikCjWXfO52MwOHBEntaq-i59ruJIDJ9Cp0NfOH0@mail.gmail.com
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] : http://stackoverflow.com/questions/2997042/where-is-the-documentation-for

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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About