通过实例学习perl的reverse,sort,scalar

发布时间:2020-09-01编辑:脚本学堂
学习perl的reverse,sort,scalar的例子,感兴趣的朋友可以参考下。[root@jbxue perl]# more reverse_sort_scalar.pl
复制代码 代码如下:#!/usr/bin/perl -w
use strict

学习perl的reverse,sort,scalar的例子,感兴趣的朋友可以参考下。

[root@jbxue perl]# more reverse_sort_scalar.pl 
 

复制代码 代码如下:
#!/usr/bin/perl -w
use strict;
#reverse
my @array_reverse = 1..3;
my @array_ed = reverse(@array_reverse);
print "数组的值为1 2 3,reverse反转数组的值为: ","@array_edn";
#sort
my @array_sort = qw/c b a/;
my @sorted = sort@array_sort;
print "数组的值为c b a,sort排序后为: ","@sortedn";
#scalar强制指定标量上下文。
my @array_scalar = qw/a b c/;
print "数组的值为abc,scalar指出数组的个数为:",scalar@array_scalar,"n";

[root@jbxue perl]# perl reverse_sort_scalar.pl
数组的值为1 2 3,reverse反转数组的值为: 3 2 1
数组的值为c b a,sort排序后为: a b c
数组的值为abc,scalar指出数组的个数为:3