6 XSLoader::load(); # This returns true, which makes require happy.
12 arybase - Set indexing base via $[
18 @a = qw(Sun Mon Tue Wed Thu Fri Sat);
19 print $a[3], "\n"; # prints Tue
23 This module implements Perl's C<$[> variable. You should not use it
26 Assigning to C<$[> has the I<compile-time> effect of making the assigned
27 value, converted to an integer, the index of the first element in an array
28 and the first character in a substring, within the enclosing lexical scope.
30 It can be written with or without C<local>:
35 It only works if the assignment can be detected at compile time and the
36 value assigned is constant.
38 It affects the following operations:
44 splice @array, $index, ...
48 index $string, $substring # return value is affected
50 substr $string, $offset, ...
52 As with the default base of 0, negative bases count from the end of the
53 array or string, starting with -1. If C<$[> is a positive integer, indices
54 from C<$[-1> to 0 also count from the end. If C<$[> is negative (why would
55 you do that, though?), indices from C<$[> to 0 count from the beginning of
56 the string, but indices below C<$[> count from the end of the string as
57 though the base were 0.
59 Prior to Perl 5.16, indices from 0 to C<$[-1> inclusive, for positive
60 values of C<$[>, behaved differently for different operations; negative
61 indices equal to or greater than a negative C<$[> likewise behaved
66 Before Perl 5, C<$[> was a global variable that affected all array indices
69 Starting with Perl 5, it became a file-scoped compile-time directive, which
70 could be made lexically-scoped with C<local>. "File-scoped" means that the
71 C<$[> assignment could leak out of the block in which occurred:
75 # ... array base is 1 here ...
77 # ... still 1, but not in other files ...
79 In Perl 5.10, it became strictly lexical. The file-scoped behaviour was
80 removed (perhaps inadvertently, but what's done is done).
82 In Perl 5.16, the implementation was moved into this module, and out of the
83 Perl core. The erratic behaviour that occurred with indices between -1 and
84 C<$[> was made consistent between operations, and, for negative bases,
85 indices from C<$[> to -1 inclusive were made consistent between operations.
89 Error messages that mention array indices use the 0-based index.
91 C<keys $arrayref> and C<each $arrayref> do not respect the current value of
96 L<perlvar/"$[">, L<Array::Base> and L<String::Base>.