1.截取屏幕输入字符串,然后根据ASCII 排序。一个字符串一行,#!/usr/bin/perl -w print "Please input string,one per line,Crtl-D:\n"; chomp(@lines = ); @sorted = sort @lines; print "You stdin strings is : \n @lines \n"; print "The sort is : \n @sorted\n";输出:You stdin strings is : a a b d c e g f The sort is : a a b c d e f g2. 自定义数组,然后获取键盘输入的数字,根据数字进行对数组遍历打印。
#!/usr/bin/perl -w #-w 为报警使用
@name = qw (a b c d e);# 定义数组
print "Enter some number from 1-5,one per line,then press Crtl-D:\n";#输入数字时,记着输一个按下回车。