in reply to Is $# still used?

I must have missed the deprecation announcement — you've quite surprised me.

$# is useful when you need an explicit index, eg., 0 .. $#arr . Sure, it's more perlish to avoid the index and iterate over the memebers directly, but sometimes you need this, for example when accessing two related arrays. (Yes, I know. If they're related then they may have been associated together in a list of hashes. Sometimes that's not appropriate though.)

In Perl 6, the .kv method operates on arrays too, yielding numeric indexes and values:

say "what is your favorite color?"; my @favorite_colors = ("blue", "red", "uhh, yellow!"); for @favorite_colors.kv -> $id, $color { say "$id. $color"; }

Replies are listed 'Best First'.
Re^2: Is $# still used?
by Zaxo (Archbishop) on Jun 11, 2005 at 10:10 UTC

    You're thinking of the "last index" construct. ghenry is talking about the output numeric format $#. It's a sprintf-style format which perl uses for stringifying numbers.

    After Compline,
    Zaxo

      Ah! I'm much less surprised now. In Perl, "there's something more" happens more often than "there's something less". :-)