Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

arybase(3pm) [osx man page]

arybase(3pm)						 Perl Programmers Reference Guide					      arybase(3pm)

NAME
arybase - Set indexing base via $[ SYNOPSIS
$[ = 1; @a = qw(Sun Mon Tue Wed Thu Fri Sat); print $a[3], " "; # prints Tue DESCRIPTION
This module implements Perl's $[ variable. You should not use it directly. Assigning to $[ has the compile-time effect of making the assigned value, converted to an integer, the index of the first element in an array and the first character in a substring, within the enclosing lexical scope. It can be written with or without "local": $[ = 1; local $[ = 1; It only works if the assignment can be detected at compile time and the value assigned is constant. It affects the following operations: $array[$element] @array[@slice] $#array (list())[$slice] splice @array, $index, ... each @array keys @array index $string, $substring # return value is affected pos $string substr $string, $offset, ... As with the default base of 0, negative bases count from the end of the array or string, starting with -1. If $[ is a positive integer, indices from "$[-1" to 0 also count from the end. If $[ is negative (why would you do that, though?), indices from $[ to 0 count from the beginning of the string, but indices below $[ count from the end of the string as though the base were 0. Prior to Perl 5.16, indices from 0 to "$[-1" inclusive, for positive values of $[, behaved differently for different operations; negative indices equal to or greater than a negative $[ likewise behaved inconsistently. HISTORY
Before Perl 5, $[ was a global variable that affected all array indices and string offsets. Starting with Perl 5, it became a file-scoped compile-time directive, which could be made lexically-scoped with "local". "File-scoped" means that the $[ assignment could leak out of the block in which occurred: { $[ = 1; # ... array base is 1 here ... } # ... still 1, but not in other files ... In Perl 5.10, it became strictly lexical. The file-scoped behaviour was removed (perhaps inadvertently, but what's done is done). In Perl 5.16, the implementation was moved into this module, and out of the Perl core. The erratic behaviour that occurred with indices between -1 and $[ was made consistent between operations, and, for negative bases, indices from $[ to -1 inclusive were made consistent between operations. BUGS
Error messages that mention array indices use the 0-based index. "keys $arrayref" and "each $arrayref" do not respect the current value of $[. SEE ALSO
"$[" in perlvar, Array::Base and String::Base. perl v5.16.2 2012-10-11 arybase(3pm)

Check Out this Related Man Page

ARRAY(3)								 1								  ARRAY(3)

array - Create an array

SYNOPSIS
array array ([mixed $...]) DESCRIPTION
Creates an array. Read the section on the array type for more information on what an array is. PARAMETERS
o $... - Syntax "index => values", separated by commas, define index and values. index may be of type string or integer. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the big- gest integer index + 1. Note that when two identical index are defined, the last overwrite the first. Having a trailing comma after the last defined array entry, while unusual, is a valid syntax. RETURN VALUES
Returns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is. EXAMPLES
The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and- continue numeric indices in normal arrays. Example #1 array(3) example <?php $fruits = array ( "fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), "numbers" => array(1, 2, 3, 4, 5, 6), "holes" => array("first", 5 => "second", "third") ); ?> Example #2 Automatic index with array(3) <?php $array = array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13); print_r($array); ?> The above example will output: Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 13 [4] => 1 [8] => 1 [9] => 19 ) Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8. This example creates a 1-based array. Example #3 1-based index with array(3) <?php $firstquarter = array(1 => 'January', 'February', 'March'); print_r($firstquarter); ?> The above example will output: Array ( [1] => January [2] => February [3] => March ) As in Perl, you can access a value from the array inside double quotes. However, with PHP you'll need to enclose your array between curly braces. Example #4 Accessing an array inside double quotes <?php $foo = array('bar' => 'baz'); echo "Hello {$foo['bar']}!"; // Hello baz! ?> NOTES
Note array(3) is a language construct used to represent literal arrays, and not a regular function. SEE ALSO
array_pad(3), list(3), count(3), range(3), foreach, The array type. PHP Documentation Group ARRAY(3)
Man Page