


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、?Perl语言入门习题答案?2.12练习1、写一个程序,计算半径为12.5的圆的周长。圆周长等于2nn约为3.1415926乘以半径。答案为78.5。/home/co nfish/perl/girth#!/usr/b in/perl -w#this program calculate a circle's girth#con fishubu ntu7.10$r=12.5;$g=12.5*2*3.1415;prin t "the girth of the circle is $gn"/home/co nfish/perl/girth2、修改上述程序,用户可以在程序运行
2、时输入半径。如果,用户输入12.5,那么应得到和上题一样的结果。/home/co nfish/perl/girthpro#!/usr/b in/perl -w#a better one to calculate girth#con fishubu ntu7.10prin t"e nter the radius of the circlen"chomp($r=<STDIN>);if($r>0)prin t"the girth of the circle is ".$r*2*3.1415."n"elseprin t&qu
3、ot; non available!n"/home/co nfish/perl/girthpro3、修改上述程序,当用户输入小于0的数字时,程序输出的周长为0,而非负数。/home/co nfish/perl/girthzero#!/usr/b in/perl -w#calculate the girth and print 0 whe n the radius is lower tha n 0#con fishub un tu7.10prin t"e nter the radius of the linen"chomp($r=<STDIN>);if(
4、$r>0)prin t"the girth of the circle is $r*2*3.1415n"elseprin t"the girth of the circle is 0n"/home/co nfish/perl/girthzero1、2、3:一起实现的#!/usr/b in/perl -w$pai=3.141592654;prin t "Please In put Radius:"$r=<STDIN>if ( $r lt 0 )print "The circumference is 0n&qu
5、ot;else$l=$r*2*$pai;printf "The circumference is %.1fn",$l;4、写一个程序,用户能输入2个数字不在同一行。输出为这两个数的积。/home/co nfish/perl/product#!/usr/b in/perl -w#pri nt the two nu mber's product#con fishubu ntu7.10prin t"e nter the two nu mbers:n"chomp($m=<STDIN>);chomp($ n=<STDIN>);pri
6、nt"the product of the two numbers are ".$m*$n."in"/home/co nfish/perl/product5、写一个程序,用户能输入1个字符串和一个数字(n)不在同一行。输出为,n行这个 字符串,1次1行提示,使用“ x操作符。例如,如果用户输入的是“fred和“ 3那么输出为:3行,每一行均为fred。如果输入为“ fred 和“ 299792,那么输出为299792行, 每一行均为fred/home/co nfish/perl/pri nter#!/usr/b in/perl -w#pri nt a s
7、tri ng certa in times depe nd on the usr's in put#con fishubu ntu7.10print"enter a string and a number:in"$str=<STDIN>chomp($ num=<STDIN>);3.9练习1、写一个程序,将一些字符串不同的行读入一个列表中,逆向输出它。如果是从键盘 输入的,那在Unix系统中应当使用 CTRL+D 说明end-of-file,在Windows系统中使用CTRL+Z./home/c on fish/repri nt#!/usr/b
8、 in/perl -w#read some in put and print them in reverse seque nee#con fishubu ntu7.10print "enter the string please:n"str=reverse <STDIN>prin t "nthe reverse stri ngs are:n str"/home/c on fish/repri nt2、写一个程序,读入一串数字一个数字一行,将和这些数字对应的人名下面列出的输出来。将下面的人名列表写入代码中。fred betty barney d
9、ino Wilma pebbles bamm-bamm例如,当输入为1,2,4和2,那么输出的为fred, betty, dino,和betty/home/c on fish/nu m_to_ name#!/usr/b in/perl -w#read some nu mbers and output the match n ame#con fishubu ntu7.10$i=0;n ames=qw /fred betty barney dino Wilma pebbles bamm-bamm/;print"enter the numbers please:n"chomp(
10、n ums=<STDIN>);foreach( nu ms)re=n ames;while($i ne $n=shift( re);$i+;$i=0;print $n ,"n"/home/c on fish/nu m to name3、写一个程序,将一些字符串在不同的行中读入一个列表中。然后按ASCII顺序将它们输出来。也就是说,当输入的字符串为fred, barney, wilma, betty,那么输出为barney betty fred wilma。分别在一行或不同的行将之输出。/home/c on fish/sort_str#!/usr/b in/per
11、l -w#read some stri ngs and sort them in ASCII#con fishubu ntu7.10 chomp(str=sort<STDIN>); #str=sort<STDIN> will print them in diffre nt li nes print str,"n"/home/c on fish/sort_str4.11练习1、写一个名为&total的子程序,返回一列数字的和。提示:子程序不应当有任何的I/O操作;它处理调用的参数,返回处理后的值给调用者。结 合下面的程序来练习,它检测此子程序是
12、否正常工作。第一组数组之和25。my fred = qw 1 3 5 7 9 ;my $fred_total = &total(fred);prin t "The total of fred is $fred_total.n"prin t "E nter some nu mbers on separate lin es:"my $user_total = &total(<STDIN>);print "The total of those numbers is $user_total.n" /home/co
13、nfish/perl/subr #!/usr/b in/perl -w#a subrout ine n amed total retur ns sum of nu mbers #con fishubu ntu7.10sub totalforeach $n (0.$#_)$sum+=$_$ n;$sum;myfred=qw1 3 5 7 9;my $fred_total=&total(fred);prin t"The total of fred is $fred_total.n"print"Enter some numbers on separate lin
14、es:n" my $user_total=&total(<STDIN>);print"The total of those numbers is $user_total.n" /home/co nfish/perl/subr2、利用上题的子程序,写一个程序计算从1到1000的数字的和。/home/co nfish/perl/suber#!/usr/b in/perl -w#use the subrouti ne in last program to get the sum of 1.1000 #con fishubu ntu7.10sub to
15、talforeach $n (O.$#_)$sum+=$_$ n;$sum;n um=(1.1000);$sum=&total( n um);prin t"The sum of 1.1000 is $sumn" /home/co nfish/perl/suber3、额外的练习:写一个子程序,名为&above_average,将一列数字作为其参数,返回所有大于平均值的数字提示:另外写一个子程序来计算平均值,总和除以数字的个数。利用 下面的程序进行测试:my fred = &above_average(1.10);prin t "fred is
16、 fredn"prin t "(Should be 6 7 8 9 10)n"my barney = & above_average(100, 1.10);prin t "bar ney is bar neyn"prin t "(Should be just 100)n"/home/co nfish/perl/aver#!/usr/b in/perl -w#to print the nu mber which is larger tha n the average#in some nu mbers#con fishu
17、bu ntu7.10sub averageforeach $n (0.$#_)$sum+=$_$ n;$average=$sum/($#_+1);sub above_averagenum=_;aba=();$av=&average( nu m);foreach $n (0.$#)if($ n>$av)push ( aba,$n);aba;my fred=&above_average(1.10);prin t"fred is fredn"prin t"(Shuold be 6 7 8 9 10)n"my barney=&abo
18、ve_average(100,1.10);prin t"bar ney is bar neyn"prin t"(Should be just 100)n"/home/co nfish/perl/aver5.11练习1、写一个程序,类似于cat,但保持输出的顺序关系。某些系统的名字可能是tac。如果运行此程序:./tac fred barney betty,输出将是文件 betty的内容,从最后一行到第一行, 然后是barney,最后是fred,同样是从最后一行到第一行。注意使用./确保调用的是你自己的程序,而非系统提供的/home/co nfish/pe
19、rl/tac#!/usr/b in/perl -w#a prog same as cat but reverse the stri ng#con fishubu ntu7.10ARGV=reverse ARGV;a=reverse<>print a;/home/co nfish/perl/tac2、写一个程序,要求用户在不同的行中输入一些字符串,将此字符串打印出来,规那么是:每一条占20个字符宽度,右对齐。为了确保正确的输出,在开头打印出一串数字作为比拟帮助调试。注意,不要犯 19个字符宽度的错误。例如,如果输入,hello, good-bye,那么输出为:hellogood-by
20、e/home/co nfish/perl/20str #!/usr/b in/perl -w#a prog that print the strings as 20 words flush right #con fishubu ntu7.10str=<STDIN>while($i!=5)foreach(0.9) print;$i+;prin t"n"foreach(str)printf "%21s",$_;/home/co nfish/perl/20str3、修改上一个程序,允许用户选择宽度,女口,用户输入30, hello, good-by
21、e(在不同的行中), 那么每一行的宽度为30。提示:参阅第二章相应局部。提示,如果选择的宽度太长,可以 增加比拟行的长度。/home/co nfish/perl/20strpro#!/usr/b in/perl-w#a prog print the stri ngs as nu mber usr api on ted words flush right #con fishubu ntu7.10str=<STDIN> while($i!=5) foreach(0.9) print;$i+;prin t "n"$num=shift str;chomp $num;$c
22、on v="%".+$ num."s"foreach(str)printf $co nv,$_;/home/co nfish/perl/20strpro6.5练习1、写一个程序,提示用户输入 given name名,并给出其对应的family name姓。使用你知道的人名,或者表6-1如果你在电脑上花了太多时间,以致什么人都不认识:表6- 1样本数据输入输出fred flin tst onebarney rubblewilma flin tst one/home/co nfish/perl/hash#!/usr/b in/perl -w#hashs th
23、at print the n ame's family n ame#con fishubu ntu7.10$family_ name"fred"="fli ntsto ne"$family_ name"bar ney"="rubble"$family_ n ame"wilma"="fli ntst on e"print "enter the given name please:n"chomp($g n=<STDIN>);print &q
24、uot;family name for $gn is $family_name$gnn"/home/c on fish/perl/hash2、写一个程序,读入一串单词(一个单词一行),输出每一个单词出现的次数。提示:如果某个作为数字使用值是 undefined的,会自动将它转换为 0。如果输入单词为 fred,barney, di no, wilma , fred 在不同行中,那么输出的fred将为/home/c on fish/perl/co unts#!/usr/b in/perl -w#hashs that counts the appeara nee times of the
25、 word#pri nt sorted#con fishubu ntu7.10prin t "e nter the word please:n"foreach(<>)$cou nts$+;$cou nts$ _.="n"sort %co un ts;print %co un ts;/home/c on fish/perl/co unts7.4练习1、写一个程序,输出所有提到fred的行不要输出其它行。如果输入字符串 Fred, f redrick, Alfred,能匹配上吗?准备一个小的文本文件,其中包含如:“ fred lintsotne
26、以及类似的信息。使用这个文本文件作为此程序的输入,以及本节下面练习的输入。/home/co nfish/perl/pfred#!/usr/b in/perl -w#prog print the line which contains "fred"#con fishubu ntu7.10foreach(<>)if(/fred/)print $_;/home/co nfish/perl/pfred2、修改上面的程序,允许匹配Fred。现在它能匹配,Fred, f redrick , Alfred 吗?将这些名字参加输入文件中/home/co nfish/perl/p
27、ffred#!/usr/b in/perl -w#prog print the line which contains "fred" or "Fred"#con fishubu ntu7.10foreach(<>)if(/fred|Fred/)print $_;/home/co nfish/perl/pffred3、写一个程序,输出出现句号(.)的行,忽略其它行。使用前面练习中的文件进行练习:它能找到 Mr. Slate吗?/home/co nfish/perl/pp#!/usr/b in/perl -w#prog print the lin
28、e which contains a point#con fishubu ntu7.10foreach(<>)if(八./)print $_;/home/co nfish/perl/pp4、写一个程序,输出有一个字母大写,而非所有字母都大写的行。它能匹配Fred,而不 匹配fred和FRED 吗?/home/co nfish/perl/plg#!/usr/b in/perl -w#pri nt the line which contains not capitals only#con fishubu ntu7.10foreach(<>) if(/a-zA-Z|A-Z+a
29、-z/)print $_;/home/co nfish/perl/plg5、额外的练习:写一个程序,它能输出所有同时提到wilma和fred的行。/home/co nfish/perl/pfw#!/usr/b in/perl -w#pri nt a line which contains fred and wilma#con fishubu ntu7.10foreach(<>)if(/wilma.+fred|fred.+wilma/)print $_;/home/co nfish/perl/pfw8.10练习1、使用模式测试程序。创造一个模式能匹配字符串match。使用字符串bef
30、orematchafter进行测试。输出结果将其三局部放在正确位置了吗?/home/c on fish/perl/mm#!/usr/b in/perl -w#match "match"#con fishubu ntu7.10while(<>)chomp;if(/match/)prin t "Matched:|$'<$&>$'|n"elseprint "no match:|$n"2、使用模式测试程序,创造一个模式能匹配任何单词 w意义下的单词,但这个单词必需以字母a结尾。 它匹配 wilm
31、a而没匹配 barney吗?它匹配 Mrs. Wilma Flintstone吗? wilma &fred呢?使用前一章习题的文件进行练习如果没有上述字符串,那么加上它们/home/co nfish/perl/ma#!/usr/b in/perl -w#match "word" ends with a#con fishubu ntu7.10while(<>)chomp;if(/ab/)prin t "Matched:|$'<$&>$'|n"elseprint "no match:|$n&q
32、uot;/home/co nfish/perl/ma3、修改第二题的程序,使之将由a结尾的单词放到$1之中。同时修改源代码,使此变量对应的值被放在单引号之中,如$1 con tai ns Wilma '。/home/co nfish/perl/mapro#!/usr/b in/perl -w#match word end with a and storage it#con fishubu ntu7.10while(<>)chomp;if(/(a$)/)my $temp=$1;prin t "$1 con tai ns '$'$ &$n&qu
33、ot;elseprint "no match:|$n"4、额外练习:修改第三题程序,使之能捕捉由a结尾的单词之后的5个字符如果有那么多,并将之放入一个独立变量中。例如,如果输入的是I saw Wilma yester day,那么紧接的5个字符是yest前有空格。如果输入是 I , Wilma!,那么只有一个字符。它现在还能 匹配wilma吗?/home/co nfish/perl/mwa#!/usr/b in/perl-w#match a word end with a and print the next five character#con fishubu ntu7.
34、10 while(<>)if(/ab/)my $temp=$'if($temp=/.0,5/)my $match=$&print $match; elseprint "no match:|$n"/home/co nfish/perl/mwa5、写一个程序不是测试程序,能输出任何由空白结尾的输入行非换行符。在输出的结尾处放置一个标记符,使之能标记出空白。/home/co nfish/perl/ms#!/usr/b in/perl -w#match a space#con fishubu ntu7.10while(<>)if(/ +$/)
35、print;/home/con fish/perl/ms9.6练习1、写一个模式,它能匹配$what当前的内容的 3份连续拷贝。也就是说,如果$what为fred, 那么此模式能匹配fredfredfred。如果$what为fred|barney,那么此模式能匹配fredfredbarney, barneyfredfred, barneybarneybarney , 或者其它的变种。提示: 你应当在程序的顶端设置 $what 的值,女口 my $what = fred|barney'/home/co nfish/perl/sfb#!/usr/b in/perl -w#match and
36、 replace fred three times#con fishubu ntu7.10my $what="fred|bar ney"if("fredbarneybarney"=/($what)3/)print $'."/".$&."/"$'"' n"/home/co nfish/perl/sfb2、写一个程序,它可以得到当前文本文件的一个拷贝。在拷贝的文件中,字符串Fred(大小写无关)将被Larry替换掉。因此,“ Manfred Mann将变成 “ Man
37、 Larry Ma nn . 输入的文件名已经在命令行中指定不需要询问用户,输出的文件名是对应的输入文件名后面加上.out。/home/co nfish/perl/sfl#!/usr/b in/perl -w#match fred to Larry#con fishubu ntu7.10$AI=".out"while(<>)s/fred/Larry/i;print;/home/co nfish/perl/sfl3、修改上面程序,使之将Fred由Wilma替换,Wilma由Fred替换。如果输入的为fred&wilma ,那么输出为 Wilma$Fred。
38、/home/co nfish/perl/addc#!/usr/b in/perl -w#add copyright#con fishubu ntu7.10$A|=".out"$a="/usr/bi n/perl -w n #Copyright(C) 2022 by Yours Truly con fish"while(<>)s#/usr/bi n/perls+-w#$a#i;print;4、额外练习:写一个程序在你所有的练习的答案前加上下面这样一行:a) # Copyright (C) 20XX by Yours Truly将上面一行放在&q
39、uot;shebang 行Perl程序的第一行,#!/usr/bin/perl可能随 Perl安装的位置而有所不同,但是指第一行,译者注下面。你应当在“源文件中修改,但请备份文件。假定你可以在命令行中同时输入程序和需要的修改的文件名。10.10练习1、写一个程序,能重复要求用户猜想某个在1到100之间的数字,直到猜对为止。你的程序应当能随机的产生一个数字,使用公式int(1 + rand 100)。当用户猜想错误时,程序应该回应“ Toohigh 或者 “ Too low 。如果用户输入 quit或exit,或者回车时,程序应立即退岀。如 果用户猜想正确,程序也退岀。/home/co nfis
40、h/perl/g n#!/usr/b in/perl -w#a game to guess a nu mber#con fishubu ntu7.10 my $y=i nt(1+ra nd(100);prin t"e nter a nu mber please:n"while(chomp($t=<STDIN>)if($t ne "exit"&&$t ne"quit")if($t>$y) prin t"tow hign"elsif($t<$y)prin t"two l
41、own" else prin t "an"last;elselast;11.6练习1、写一个程序,读入命令行中的一串文件,报告其是否可读,可写,可执行,或不存在。提示:如果一个函数能一次对一个文件进行所有的检测将非常有帮助。如果一个文件被执行了 chmod 0操作, 将报告什么?在 Unix系统中,chmod 0 some_file 将一个文 件变成不可读,不可写,不可执行的在大多数 shell中,星号*表示当前目录中的所 有的普通文件。也就是说,可以输入像./ex11 -1 *这样的命令,返回当前目录下文件的属性。/home/co nfish/perl/crw#
42、!/usr/b in/perl -w#to check whether a file is exits have readability and writeable #con fishubu ntu7.10 foreach(ARGV)if(-e) prin t "$_ exits'n"if(-r) prin t "$_ readable'n"elseprin t"$_ does not be readablen" if(-w)prin t "$_ writeablen"elseprin t &quo
43、t;$_ does not be writeablen"elseprin t "$ does not exitsn"/home/co nfish/perl/crw2、写一个程序,找出命令行中存在时间最长的文件名,并报告其天数。当参数为空时,其 行为如何例如,命令行中没有输入任何的文件?/home/co nfish/perl/et#!/usr/b in/perl -w#to check the Ion gest exits file#con fishubu ntu7.10if(ARGV)foreach(ARGV)if(-M>$such)$such=-M;$fi
44、le=$_;prin t"$file has exits $such daysn"elseprint "no in put filesn"/home/co nfish/perl/et12.14练习1、写一个程序要求用户输入一个目录名,再改变到那个目录去。如果用户输入的值是空白,那么转变到他/她的主目录去。改变后,将这个目录下的普通内容不包括有点.开头的项 按照字母顺序列出来。提示:使用目录句柄还是glob更方便?如果没有成功改变目录,提示用户,但不要尝试输出目录里的内容。#! /usr/b in/env perl -wuse strict;#Date:2
45、005-05-31#ex12_1if (ARGV) chdir $ARGV0;elsechdir ""_=glob '*'print _;2、修改程序,使之包含所有的文件,不仅仅是那些不以点(.)开头的文件。#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex12_1if (ARGV) chdir $ARGVO;elsechdir ""_=glob '.* *'print _;3、如果你在前面的练习中使用的是目录句柄,使用glob重写它。如果使用的是那么用目录句柄重写
46、。#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex12_3prin t "Which directory? (Default is your home directory)"chomp(my $dir = <STDIN>);if ($dir = /As*$/) # A bla nk linechdir or die "Ca n't chdir to your home directory:$!" else chdir $dir or die "Can't c
47、hdir to '$dir': $!"opendir DOT, "." or die "Can't opendir dot: $!"foreach (sort readdir DOT) # n ext if /a./; # if we were skipp ing dot files prin t "$_ n"4、写一个类似于rm的程序,删除命令行中出现的任何文件。不需要处理像项#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex12_4#类似于
48、rm的程序for (ARGV) un li nk $;glob ,rm中的选不需要处5、写一个类似于 mv的程序,将命令行中的第一个参数重命名为第二个参数。(base name),生成新的目录。#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex12_5#类似于mv的程序ren ame $ARGV0,$ARGV1;6、如果你的操作系统支持,写一个类似于In的程序,能建立命令行中第一个参数的硬连接(hard link)到第二个参数。不需要处理ln的选项,或者更多的参数。如果系统没有硬连接,那么输出一条消息,指出如果可行你将进行的操作。提示:
49、这个程序和前面的有类似的地方,注意到这一点能节约你编码的时间。#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex12_5#类似于ln的程序link $ARGV0,$ARGV1or warn "can't lin k"7、如果你的操作系统支持,修改上一个练习的程序,使之支持-s选项在别的参数前面,来说明你想创立一个软连接(soft I ink)而非(hard link)。(甚至在你没有硬连接的情况,你也有可能能创立软连接。)#! /usr/b in/env perl -wuse strict;#Date:200
50、5-05-31#ex12_5#类似于ln -s的程序symli nk $ARGV0,$ARGV1or warn "can't symli nk"8、如果你的操作系统支持,写一个程序来查找当前目录下的符号连接symbolic links,并将它们的值打印出来如ls - l 一样:name - > value丨。#!/usr/b in/perl -wuse strict;uni ess(ARGV) die "perl $0 <dir>n"my file=glob "$ARGV0/*"foreach(file) c
51、homp $_;my $li nk=readli nk "$_"if(defi ned $li nk)pri nt "$_ -> $li nkn"a='ls l|grep - e ->'13.5练习1、写一个程序,读入一串数字,将它们按照数字排序,将结果按右对齐的列打印出来。使 用下面的数据进行检测:17 000 04 1.50 3.14159 - 10 1.5 4 2001 90210 666#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex13_1#读入一串数字,将
52、它们按照数字排序,将结果按右对齐的列打印出来_=(17,000,04,1.50,3.14159,-10,1.5,4,2001,90210,666);_=sort $a<=>$b_;for (_)$_=spri ntf "%8sn",$_;print ;2、写一个程序,将下例 hash数据根据姓last name按照大小写无关的字母顺序进行排 序,并把结果打印出来。当last name相同时,再按照名(firs t name)排序不用关心大小写。 因此,第一个输出的的名字是Fred's,最后一个是Betty's。具有相同family name名字在
53、一起。不要改变数据。输知名字的大小写应当和这里的一样。my %last_ name = qwfred flin tst one Wilma Fli ntst one Barney Rubblebetty rubble Bamm- Bamm Rubble PEBBLES FLINTSONE;#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex13_2#my keys = sort "L$last_ name$a" cmp "L$last_ name$b"# by last nameor"L$
54、a" cmp "L$b"# by first name keys %last_ name;foreach (keys) prin t "$last_name$_, $_n"# Rubble,Bamm-Bamm3、写一个程序,查找给定子串在给定字符串中出现的每一个位置,输出子串出现的位置。例如,给定字符串为“This is a test 给定子串为“is ,它应当输出2和5。如果子串是“ a 它应当输出8。如果子串为“ t呢?#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex13_3#查找
55、给定子串在给定字符串中出现的每一个位置,输出子串出现的位置my $a="This is a test"my $b="Th"my $c=-2;while ($c+1)$c=i ndex($a,$b,$c+1);prin t "$cn"14.8练习1、写一个程序可以转到某个特定的写入代码中的目录,如系统的根目录,再执行ls -l得到那个目录的目录列表。如果你的是 non-Unix系统,使用你自己的系统命令,得到那个目录的详细列表#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex14
56、_1#程序可以转到某个特定的目录,再执行ls - l得到目录列表chdir ""system "dir"2、修改第一题的程序,将结果输出到当前目录的文件ls.out中。错误的结果输出到文件ls.err中。你不需要做任何特殊的事,这两个文件中的任意一个都可能是空的。#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex14_1#将结果输出到当前目录的文件ls.out中。错误的结果输出到文件ls.err中chdir ""open LOG,"»14_2.out&quo
57、t;open STDERR,"»14_2.err"my $d= 'dir'print LOG"$d"3、写一个程序能解析date命令的输出,判断当前日期是一个星期的第几天。如果是weekday周一至周五,那么输出 get to work ;否那么,输出 go play。 date命令的输出如果 是由Mon开头,那么指星期一。如果你的 non-Unix系统没有date命令,那么伪造一个程序使之可以输出像date命令那样的结果。我们这里给你提供一个两行的程序,如果你容许不问我们它工作的原因:#! /usr/b in/env perl -wuse strict;#Date:2005-05-31#ex14_1#判断当前日期是一个星期的第几天。如果是weekday周一至周五,那么输出#get to work ;否那么,输出 go play。if ('date' = /AS/) prin t "go play!n" else prin t "get to work!n"15.4练习1、从CPAN上安装 Module:CoreList这个模块。打印出 Perl5.006所附
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 课件汇报表格
- 车间导师师傅培训
- 环宇物流文员培训
- 特教语言课课件
- 枇杷美术创意课件
- 创意美术花瓶课件
- 课件最后的人生寄语
- 课件显示无法复制问题
- 雷达液位计考试题及答案
- 蓝山教练考试题及答案
- 古诗词诵读教学设计与实施方案
- 2025年山东省政府采购评审专家考试题库附含答案
- 重庆市南开中学高2026届高三第一次质量检测+数学答案
- GJB135B-2021合成航空发动机润滑油规范
- 商业航天行业深度报告:政策技术需求共振商业航天赛道加速
- 小学科学新教科版二年级上册第一单元 造房子教案(共6课)(2025秋)
- 《系统工程》课件 胡祥培 第1-3章 绪论、系统工程相关理论、系统工程方法论
- 《人工智能基础》课件-AI的前世今生:她从哪里来
- 四川普通高中会考英语试卷及答案
- 营造林技能竞赛试题及答案
- 科比受伤及励志
评论
0/150
提交评论