Perl为数组排序
2015-07-30 22:23
225 查看
1 #!/usr/local/bin/perl5 2 use strict; 3 use warnings; 4 use Data::Dumper; 5 my @array=(8,99,90); 6 my $maxCnt = &max(@array); 7 sub max { my $currentMaxCnt = shift @_; 8 foreach ( @_ ) 9 { if ( $_ > $currentMaxCnt ) 10 { 11 $currentMaxCnt = $_; 12 } 13 } 14 return $currentMaxCnt; 15 } 16 print $maxCnt,"\n"; ~ ~ ~ ~ ~ ~ ~ 0mnsdev13:scripts> ls FASTA FASTA.pl* oekb_xml_download_url.pl FASTA.PL FASTa.pl oekb_xml_parse_load.pl FASTA.out fasta.pl pl mnsdev13:scripts> ./FASTA.pl 99 mnsdev13:scripts>
2.
#!/usr/local/bin/perl5 2 use strict; 3 use warnings; 4 use Smart::Comments; 5 my @array=(3,7,5,9); 6 my @arr=sort@array; 7 ###@arr; 8 print $array[3];
3.
1 #!/usr/local/bin/perl5 2 use strict; 3 use warnings; 4 my @array = (8,99,90); 5 print join ('',sort@array),"\n"; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 0mnsdev13:scripts> ls FASTA FASTA.pl* oekb_xml_parse_load.pl FASTA.PL fasta.pl pl FASTA.out oekb_xml_download_url.pl mnsdev13:scripts> FASTA.pl ksh: FASTA.pl: not found mnsdev13:scripts> ./FASTA.pl 89099 mnsdev13:scripts>
4.
1 #!/usr/local/bin/perl5 2 use strict; 3 use warnings; 4 my @array = (); 5 6 7 while (1) { 8 print "input a number or <enter> to finish: "; 9 my $a=<STDIN>; 10 chomp ($a); 11 12 if ($a eq "") { 13 last; 14 } 15 print "input $a\n"; 16 push(@array, $a); 17 } 18 19 print "\narray=@array\n"; 20 21 my @sorted_array = sort @array; 22 23 printf "\nsorted_array = @sorted_array\n"; ~ ~ ~ ~ ~ ~ 0mnsdev13:scripts> ls FASTA FASTA.pl* pl FASTA.PL oekb_xml_download_url.pl FASTA.out oekb_xml_parse_load.pl mnsdev13:scripts> ./FASTA.pl input a number or <enter> to finish: 1 input 1 input a number or <enter> to finish: a input a input a number or <enter> to finish: b input b input a number or <enter> to finish: ddfg input ddfg input a number or <enter> to finish: ffsgs input ffsgs input a number or <enter> to finish: f input f input a number or <enter> to finish: s input s input a number or <enter> to finish: d input d input a number or <enter> to finish: d input d input a number or <enter> to finish: sorted_array=1 a b ddfg ffsgs f s d d input sorted_array=1 a b ddfg ffsgs f s d d
5.REALBasic折叠
Private Sub Form_Load()Dim a,c As Variant
Dim i As Integer,j As Integer,temp As Integer
a = Array(17,45,12,80,50)
For j = 0 To UBound(a) - 1
For i = 0 To UBound(a) - 1
If (a(j) > a(i)) Then
temp = a(j)
a(j) = a(i)
a(i) = temp
End If
Next
Next
For i=0 to UBound(a)
msgbox str(a(i))
Next
End Sub
相关文章推荐
- js如何判断一个对象是不是Array?
- MRC模式下生成的类对象自动使用 autorelease
- C语言实现双向链表删除节点、插入节点、双向输出等操作
- 最流行的Java应用服务器排行
- android 定时器的使用
- 单片机中C语言指针与变量
- jQuery实现对P标签的操作
- C++中的运算符重载
- 探讨Unity3d跨平台原理
- 点到圆弧的距离(csu1503)+几何
- android 定时器的使用
- android 定时器的使用
- hdu 5301(枚举) Buildings
- C++ 智能指针详解
- apache服务器 403错误 禁止访问解决办法
- 高级声明(——C primer第13章)
- Android开发基础之菜单键的使用
- android 定时器的使用
- JAVA NIO的理解
- 谈谈闭包