Re: proposed addition to perlvar
[email protected] ("Chas. Owens")
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Jun 15, 2010 at 08:41, Aristotle Pagaltzis <[email protected]> wrote: > * Abigail <[email protected]> [2010-06-09 23:05]: >> In a section showing an example of '$#', the example should >> preferable have as few other things as possible - I would >> prefer the above over any foreach construct. These lines are >> about $#. Not foreach. Not ranges. And it is code that people >> will encounter - and consult the documentation for. > > The code they will encounter by far the most is `0 .. $#foo`. By > your own argument, that would ideally be part of the examples. > > > * Chas. Owens <[email protected]> [2010-06-09 18:00]: >> C<$#> is also used as sigil, which, when prepended on the name of an >> array or applied to an array reference gives the index of the last >> element in that array. > > Too many details. (Typical documentitis.) Less is more: > > C<$#> is also an alternative sigil for arrays which yields > the index of the last element. > > The examples should make plenty clear what that means. > > > diff --git a/pod/perlvar.pod b/pod/perlvar.pod > index 6c04c2e..8f001aa 100644 > --- a/pod/perlvar.pod > +++ b/pod/perlvar.pod > @@ -1651,8 +1651,8 @@ C<$#> 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: C<$# is no longer supported>. > > -C<$#> is also used as sigil, which, when prepended on the name of an > -array, gives the index of the last element in that array. > +C<$#> is also an alternative sigil for arrays which yields the index > +of the last element. > > my @array = ("a", "b", "c"); > my $last_index = $#array; # $last_index is 2 > That is much cleaner while still being correct. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read.