📌  相关文章
📜  perl - for ($i=0; $i <scalar(@array); $i++) - Whatever Code Example

📅  最后修改于: 2022-03-11 14:59:12.142000             🧑  作者: Mango

代码示例1
@array = (1, 2, 'three', $file_handle, undef);
$array[1]                  #=> 2    ## Second element array (start counting at 0)
@array[1,2]                #=> (2, 'three') ## A "slice" as list of elements selected from array
@array[1,2] = (12, 13);    #=> Assigns multiple array items

$#array                    #=> 4    ## Last element index (0..n) of array, -1 if empty.
scalar(@array)             #=> 5    ## Number of elements in the array, 0 if empty.

push @array, 123;                   ## Appends value(s) to the end of the array
pop  @array;               #=> 123  ## Removes and returns the last element of the array
unshift @array, 123;                ## Prepends value(s) onto the head of the array
shift @array               #=> 123  ## Removes and returns the first element from the array

foreach $element (@array) { # The foreach structure iterates over the loop
  print $element
}

for ($i=0; $i