On Wed, May 27, 2009 at 7:05 AM, John Macdonald <j...@perlwolf.com> wrote: > On Tue, May 26, 2009 at 04:38:21PM -0700, yary wrote: >> perl4-perl5.8 or so had a variable that let you change the starting >> index for arrays, so you could actually make the above work. But then >> everyone who'd re-arranged their brains to start counting at 0, and >> written code that has a starting index of 0, would have problems. > > That was $[ and it goes back to perl 1 or so. I recall > experimenting with it a couple of times. Using it, though, > means that you have to use $[ as the lower range limit for > *every* array everywhere.
Is it still a global in Perl 6? I've noticed a trend toward using less expansive scopes, so that setting $[ to 1 might mean that arrays that are defined in the current scope are 1-based instead of 0-based, whereas arrays defined in other scopes (such as inside a function imported from a module) might continue to be 0-based. > That gets stale very quickly, and I then decided that I would > just never change the setting of $[ and would remove such a > change from any code that I called. ...which is probably the cleanest way to handle it. It's for a similar reason that postcircumfix:<[ ]> always uses $[-based consecutive integers for indexing: you always have a consistent way of referring to, e.g., "the first element" (@x[0]) or "the last element" (@x[*-1]), without having to worry about which indexing scheme any particular array might be using. That's also the reason for custom indexing: if you _want_ to use 1-based indexing for a given array, you can always define a custom index and then refer to the first element by saying "@x{1}'. -- Jonathan "Dataweaver" Lang