ImageVerifierCode 换一换
格式:DOCX , 页数:31 ,大小:25.13KB ,
资源ID:16451284      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16451284.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Perl练习题DOCWord文件下载.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Perl练习题DOCWord文件下载.docx

1、写一个程序,用户能输入1 个字符串和一个数字(n)(不在同一行)。输出为,n 行这个字符串,1 次1 行(提示,使用“x”操作符)。例如,如果用户输入的是“fred”和“3”,则输出为:3 行,每一行均为fred。如果输入为“fred”和“299792”,则输出为299792 行,每一行均为fred。/usr.bin/perl$string=$int=$output=$string x $intprint $output;3.9练习写一个程序,将一些字符串(不同的行)读入一个列表中,逆向输出它。如果是从键盘输入的,那在Unix 系统中应当使用CTRL+D 表明end-of-file,在Wind

2、ows 系统中使用CTRL+Z. 写一个程序,读入一串数字(一个数字一行),将和这些数字对应的人名(下面列出的)输出来。(将下面的人名列表写入代码中)。fred betty barney dino Wilma pebbles bamm-bamm例如,当输入为1,2,4 和2,则输出的为fred, betty, dino, 和betty 写一个程序,将一些字符串(在不同的行中)读入一个列表中。然后按ASCII 顺序将它们输出来。也就是说,当输入的字符串为fred, barney, wilma, betty,则输出为barney betty fred wilma。分别在一行或不同的行将之输出。1:

3、/usr/bin/perl -wmichael=reverse();print michael或:userinput=foreach (userinput)unshift (array,$_);array is arrayn2:name=qw(fred betty barney dino Wilma pebbles bamm-bamm);number=foreach (number)$name$_-1n3:array=array=sort array;array4.11练习写一个名为&total 的子程序,返回一列数字的和。提示:子程序不应当有任何的I/O 操作;它处理调用的参数,返回处理后的

4、值给调用者。结合下面的程序来练习,它检测此子程序是否正常工作。第一组数组之和我25。my fred = qw 1 3 5 7 9 ;my $fred_total = &total(fred);The total of fred is $fred_total.nEnter some numbers on separate lines: my $user_total = &total(The total of those numbers is $user_total.n利用上题的子程序,写一个程序计算从1 到1000 的数字的和。额外的练习:写一个子程序,名为&above_average,将一列数

5、字作为其参数,返回所有大于平均值的数字(提示:另外写一个子程序来计算平均值,总和除以数字的个数)。利用下面的程序进行测试:my fred = &above_average(1.10);fred is fredn(Should be 6 7 8 9 10)nmy barney = &above_average(100, 1.10);barney is barneyn(Should be just 100)n#Date:2009-6-12# Exercise 4-1use strict;sub total my $sum=shift _; foreach (_) $sum=$sum+$_; $su

6、m;my fred=qw 1 3 5 7 9;my $fred_total=&The Total of fred is $fred_total.nThe Total of those numbers is $user_total.n Exercise 4-2my array=1 . 1000;my $array_total=&total(array);The sum of 1 to 1000 is $array_total.n Exercise 4-3sub average my $number=_; my $array_average=$sum/$number;sub above_avera

7、ge my above; if ($_&average(_) push above,$_;above;my above_fred = &above_average(1 . 10);The above average of fred is above_frednmy above_barney = &above_average(100, 1 . 10);The above average of barney is above_barneyn5.11练习写一个程序,类似于cat,但保持输出的顺序关系。(某些系统的名字可能是tac。)如果运行此程序:./tac fred barney betty, 输

8、出将是文件betty 的内容,从最后一行到第一行,然后是barney, 最后是fred, 同样是从最后一行到第一行。(注意使用./确保调用的是你自己的程序,而非系统提供的) 写一个程序,要求用户在不同的行中输入一些字符串,将此字符串打印出来,规则是:每一条占20 个字符宽度,右对齐。为了确保正确的输出,在开头打印出一串数字作为比较(帮助调试)。注意,不要犯19 个字符宽度的错误。例如,如果输入,hello, good-bye,则输出为:123456789012345678901234567890123456789012345678901234567890 hello good-bye 修改上一

9、个程序,允许用户选择宽度,如,用户输入30,hello, good-bye(在不同的行中),则每一行的宽度为30。(提示:参阅第二章相应部分)。提示,如果选择的宽度太长,可以增加比较行的长度。2009-6-18 Exercise 5-1print reverse 2-3: Exercise 5-2What column width would you like?chomp (my $width = Enter some lines, then press Ctrl+D:nchomp (my line = 1234567890 x ($width+9)/10), foreach (line) p

10、rintf %$widthsn, $_;chapter21.-/home/confish/perl/girth#this program calculate a circles girth#confishubuntu7.10$g=12.5*2*3.1415;the girth of the circle is $gn2.-/home/confish/perl/girthpro#a better one to calculate girthprintenter the radius of the circlenchomp($r=0) printthe girth of the circle is

11、 .$r*2*3.1415.elsenonavailable!3.-/home/confish/perl/girthzero#calculate the girth and print 0 when the radius is lower than 0enter the radius of the linenthe girth of the circle is $r*2*3.1415nthe girth of the circle is 0n4.-/home/confish/perl/product#print the two numbers productenter the two numb

12、ers:chomp($m=chomp($n=the product of the two numbers are .$m*$n.5.-/home/confish/perl/printer#print a string certain times depend on the usrs inputenter a string and a number:$str=chomp($num=print $strx$num;chapter3-/home/confish/reprint#read some input and print them in reverse sequenceenter the st

13、ring please:str=reverse nthe reverse strings are:nstr-/home/confish/num_to_name#read some numbers and output the match name#confishubuntu7.10 $i=0;names=qw /fred betty barney dino Wilma pebbles bamm-bamm/;enter the numbers please:chomp(nums=foreach(nums) re=names; while($i ne $_) $n=shift( re); $i+;

14、 $i=0; print $n,-/home/confish/sort_str#read some strings and sort them in ASCIIchomp(str=sort#str=sort$av) push ( aba,$_$n); aba;my fred=&(Shuold be 6 7 8 9 10)nmy barney=&above_average(100,1.10);chapter5-/home/confish/perl/tac#a prog same as cat but reverse the stringARGV=reverse ARGV;a=reversepri

15、nt a;-/home/confish/perl/20str#a prog that print the strings as 20 words flush rightstr=while($i!=5) foreach(0.9) print;foreach(str) printf %21s,$_;-/home/confish/perl/20strpro#a prog print the strings as number usr apionted words flush right$num=shift str;chomp $num;$conv=%.+$num.s printf $conv,$_;chapter6-/home/confish/perl/hash#hashs that print the names family name#confishu

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1