in reply to RE: Should I use $ and $# ?
in thread Should I use $ and $# ?

I didn't have the foresight to note who it was, or even what the topic was, but I do remember the drift of the topic. Somebody had asked a question that dealt with iterating over an array. One of the first posts suggested using $# as the upper limit of the for. A later post suggested using $[ as the lower limit, since there was no guarantee that the array began at index 0. I'll keep searching. It would be good for me to find again, since the details of that topic may be completely different than what I'm concerned about.
  • Comment on (Guildenstern) REx2: Should I use $ and $# ?

Replies are listed 'Best First'.
(adam: $# is not $#_) RE:(3) Should I use $ and $# ?
by Adam (Vicar) on Aug 11, 2000 at 22:25 UTC
    Ok, I see where you are going with this. I used to use $[ like that too, but it's both hard to read and unnecessary unless you alter it somewhere else. So if you don't touch $[ anywhere, there is no reason not to use 0. Besides, its somewhat deprecated.

    As for $#, that has to do with formatting print statements... not array boundaries, unless of course, you meant $#arrayName which is the index of the last element of the specified array and certainly not deprecated. In fact, not only does it give you the last index, but you can use it as an lvalue to change the size of an array.

    (And yes, the use of $# by itself to alter the formatting of print statements is highly deprecated and should not be used.)

      That's pretty much the consensus that I've arrived at. No need to use $[, since according to the docs, it's set to 0 anyway. $# in a list context seems to be perfectly okay, and it definitley(sp?) saves time and effort.
      I hear what you're saying about $[ being hard to read. Looking at code that says: $array[$[] .... it takes more than a casual glance to know what's going on.