in reply to Re: $[ is under respected.
in thread $[ is under respected.

You still suffer from the same problem, you assume that 1 is the begining of the array, and that scalar(@arr) == ($#arr+1). That makes you dually wrong if $[ = 1;


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re^3: $[ is under respected.
by Tanktalus (Canon) on Aug 03, 2005 at 03:32 UTC

    Yes ... but don't do that. Having $[ set to anything other than 0 is just asking for a world of trouble. Most modules won't cooperate, for starters. Having a global variable define the lower-bound of your arrays is going to give you issues. The right way to do this in any script of reasonable length (e.g., uses any other modules) is to be able to specify on a variable-by-variable basis what the minimum (and, optionally, maximum) index(es) is(are). Which is how any other language of note does it, if they do it at all.

    Perhaps perl6 will have that. But perl5 doesn't, so don't do that.

      I had assumed (perhaps wrongly) that the original post was tongue-in-cheek. We all know that $[ is not under-respected, but deprecated, right?
      A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: $[ is under respected.
by itub (Priest) on Aug 03, 2005 at 03:51 UTC
    Not really, for (1 .. @foo) will always loop once per array element. Where did I say that I intended to use $_ as an index to get at the elements of @foo? ;-)