Documentation for routine [ ]

Documentation for routine [ ], assembled from the following types:

language documentation Operators

From Operators

(Operators) circumfix [ ]

The Array constructor returns an itemized Array which does not flatten in list context.

language documentation Operators

From Operators

(Operators) postcircumfix [ ]

sub postcircumfix:<[ ]>(@container**@index,
                        :$k:$v:$kv:$p:$exists:$delete)

Universal interface for positional access to zero or more elements of a @container, a.k.a. "array indexing operator".

my @alphabet = 'a' .. 'z';
say @alphabet[0];                   # OUTPUT: «a␤» 
say @alphabet[1];                   # OUTPUT: «b␤» 
say @alphabet[*-1];                 # OUTPUT: «z␤» 
say @alphabet[100]:exists;          # OUTPUT: «False␤» 
say @alphabet[1541711].join;  # OUTPUT: «perl␤» 
say @alphabet[23 .. *].perl;        # OUTPUT: «("x", "y", "z")␤» 
 
@alphabet[12= "B""C";
say @alphabet[0..3].perl            # OUTPUT: «("a", "B", "C", "d")␤» 

See Subscripts, for a more detailed explanation of this operator's behavior, and how to implement support for it in custom types.