This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test $x=wait under arybase
[perl5.git] / ext / arybase / arybase.pm
CommitLineData
b82b06b8
FC
1package arybase;
2
3our $VERSION = "0.01";
4
5require XSLoader;
6XSLoader::load(); # This returns true, which makes require happy.
7
8__END__
9
10=head1 NAME
11
12arybase - Set indexing base via $[
13
14=head1 SYNOPSIS
15
16 $[ = 1;
17
18 @a = qw(Sun Mon Tue Wed Thu Fri Sat);
19 print $a[3], "\n"; # prints Tue
20
21=head1 DESCRIPTION
22
23This module implements Perl's C<$[> variable. You should not use it
24directly.
25
26Assigning to C<$[> has the I<compile-time> effect of making the assigned
27value, converted to an integer, the index of the first element in an array
28and the first character in a substring, within the enclosing lexical scope.
29
30It can be written with or without C<local>:
31
32 $[ = 1;
33 local $[ = 1;
34
35It only works if the assignment can be detected at compile time and the
36value assigned is constant.
37
38It affects the following operations:
39
40 $array[$element]
41 @array[@slice]
42 $#array
43 (list())[$slice]
44 splice @array, $index, ...
45 each @array
46 keys @array
47
48 index $string, $substring # return value is affected
49 pos $string
50 substr $string, $offset, ...
51
52As with the default base of 0, negative bases count from the end of the
53array or string, starting with -1. If C<$[> is a positive integer, indices
54from C<$[-1> to 0 also count from the end. If C<$[> is negative (why would
55you do that, though?), indices from C<$[> to 0 count from the beginning of
56the string, but indices below C<$[> count from the end of the string as
57though the base were 0.
58
59Prior to Perl 5.16, indices from 0 to C<$[-1> inclusive, for positive
60values of C<$[>, behaved differently for different operations; negative
61indices equal to or greater than a negative C<$[> likewise behaved
62inconsistently.
63
64=head1 HISTORY
65
66Before Perl 5, C<$[> was a global variable that affected all array indices
67and string offsets.
68
69Starting with Perl 5, it became a file-scoped compile-time directive, which
70could be made lexically-scoped with C<local>. "File-scoped" means that the
71C<$[> assignment could leak out of the block in which occurred:
72
73 {
74 $[ = 1;
75 # ... array base is 1 here ...
76 }
77 # ... still 1, but not in other files ...
78
79In Perl 5.10, it became strictly lexical. The file-scoped behaviour was
80removed (perhaps inadvertently, but what's done is done).
81
82In Perl 5.16, the implementation was moved into this module, and out of the
83Perl core. The erratic behaviour that occurred with indices between -1 and
84C<$[> was made consistent between operations, and, for negative bases,
85indices from C<$[> to -1 inclusive were made consistent between operations.
86
87=head1 BUGS
88
89Error messages that mention array indices use the 0-based index.
90
91C<keys $arrayref> and C<each $arrayref> do not respect the current value of
92C<$[>.
93
94=head1 SEE ALSO
95
96L<perlvar/"$[">, L<Array::Base> and L<String::Base>.
97
98=cut