@fred = 6..10;
@barney = reverse(@fred);
print "@barney";
NOTE:reverse返回逆转的列表,它不会改变其参数的值。如果返回值没有赋值给某个变量,那这个操作是没有什么意义的
11.sort操作
sort 操作将输入的一串列表(可能是数组)根据内部的字符顺序进行排序。
@rocks = qw/ bedrock slate rubble granite /;
@sorted = sort(@rocks);
print "@sorted";
12.标量和列表上下文
NOTE:一个给定的表达式在不同的上下文(contexts)中其含义是不同的。
上下文是指表达式存在的地方。当Perl解析表达式时,它通常期望一个标量值或者列表值。这既称为表达式的上下文环境。
@people = qw( fred barney betty );
@sorted = sort @people;
$number = 42 + @people;
print "@sorted";#列表context:barney , betty, fred
print "n";
print "$number";#标量context:42+3,得到45
13.在标量Context中使用List-Producing表达式
@backwards = reverse qw / yabba dabba doo /;
print "@backwards"; #返回doo, dabba, yabba
print "n";
$backwards = reverse qw/ yabba dabba doo /;
print "$backwards"; #返回oodabbadabbay
14.在列表Context中使用Scalar-Producing表达式
如果一个表达式不是列表值,则标量值自动转换为一个元素的列表。
@fred = 6*7;
@barney = "hello".' '. "world";
print "@fred"; #返回42
print "@barney"; #返回hello world
15.强制转换为标量Context
有时可能需要标量context 而Perl期望的是列表。这种情况下,可以使用函数scalar。它不是一个真实的函数因为其仅是告诉Perl提供一个标context:
@rocks = qw(talc quartz jade obsidian);
print "How many rocks do you have?n";
print "I have ", @rocks, "rocks!n"; #错误,输出rocks 的名字
print "I have ", scalar @rocks, "rocks!n"; #正确,输出其数字
NOTE:没有对应的函数能强制转换为列表context。









