- 论坛徽章:
- 0
|
我觉得,一个正常的函数在做return @array;的时候就是返回了一个数组。
不能说func2返回的不是数组,但 ...
py 发表于 2010-08-06 09:19
perldoc -q "a list and an array"
What is the difference between a list and an array?
An array has a changeable length. A list does not. An array is something
you can push or pop, while a list is a set of values. Some people make
the distinction that a list is a value while an array is a variable.
Subroutines are passed and return lists, you put things into list
context, you initialize arrays with lists, and you "foreach()" across a
list. "@" variables are arrays, anonymous arrays are arrays, arrays in
scalar context behave like the number of elements in them, subroutines
access their arguments through the array @_, and "push"/"pop"/"shift"
only work on arrays.
As a side note, there's no such thing as a list in scalar context. When
you say
$scalar = (2, 5, 7, 9);
you're using the comma operator in scalar context, so it uses the scalar
comma operator. There never was a list there at all! This causes the
last value to be returned: 9.
我是看过这段话,所以一直记得,return 的是 list …… |
|