Perl语言入门习题库chaper9习题

Perl语言入门习题库chaper9习题

码农世界 2024-05-18 前端 86 次浏览 0个评论

chapter9.1.pl

#!/usr/bin/perl -w
WangFengQiang A
my $what ='fred|barney';
while(<>){
chomp;
my $what_three = $what x 3;
if(/$what_three/) {
 print"It's Matched!\n";
}
else {
  print"No Match!\n";
}
}

chapter9.2.pl

#!/usr/bin/perl -w
##CopyRight(C) 2021 By WangFengQiang!
$^I = ".out";
while(<>){
s/Fred/Temp/ig;
s/Wilma/Fred/ig;
s/Temp/Wilma/ig;
print;
}

chapter9.3.pl

#!/usr/bin/perl -w
$^I = ".out";
while(<>){
  if(m{#!/usr/bin/perl}){
    print"##CopyRight(C) 2021 By WangFengQiang!\n$_";
  }
  else {
    print;
  }
}

chapter9.4.pl

#!/usr/bin/perl -w
$^I = ".out";
while(<>){
  if(m{copyright}i){
    print;
  }
  
  if(m{#!/usr/bin/perl}) {
    print"#WangFengQiang CopyRight\n$_";
  }
  else {
    print;
  }
}

chapter9.5.pl

#!/usr/bin/perl -w
my %a;
foreach(@ARGV){
 $a{$_} = 1;
}
while(<>){
 if(m/CopyRight/ig) {
  delete $a{$ARGV}; 
 }
}
if(%a){
@ARGV = sort keys %a;
$^I = ".out";
while(<>){
print;
  if(m{#!/usr/bin}){
    print"WangFengQiang A\n";
    }
  }
}

转载请注明来自码农世界,本文标题:《Perl语言入门习题库chaper9习题》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,86人围观)参与讨论

还没有评论,来说两句吧...

Top