14. reverse 操作符
- 读取列表的值(一般来自数组),并按照相反次序返回新的列表。
- 只是返回倒序后的列表,不会修改原始参数。
my @fred = 1..5;
print "@fred\n";
my @barney = reverse (@fred);
print "@barney\n";
my @wilma = reverse 1..5;
print "@wilma\n";
@fred = reverse @fred;
print "@fred\n";
@fred = (1..5, 11..15, 21..25);
print "@fred\n";
@barney = reverse @fred;
print "@barney\n";
15. sort操作符
- 读取列表的值(一般来自数组),依次按字符的内部编码对它们进行排序。
- 大写字符排在小写字符前,数字排在字母前,标点符号散落各处。
- 只返回排序后的新列表,不会修改原始参数。
my @rocks = qw( bedrock slate rubble granite );
print "@rocks\n";
my @sort_rocks = sort (@rocks);
print "@sort_rocks\n";
my @sort_rocks = sort @rocks;
print "@sort_rocks\n";
@sort_rocks = reverse sort @rocks;
print "@sort_rocks\n";
my @numbers = sort (1..5, 11..15, 21..25);
print "@numbers\n";
网友评论