当前位置:   article > 正文

Perl语言入门习题库chaper12习题

Perl语言入门习题库chaper12习题

chapter12.1.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Directory!\n";
  3. my $dir = <STDIN>;
  4. chomp $dir;
  5. if($dir) {
  6. chdir "$dir" or die "cannot chdir to $dir:$!"; #Go To $Dir Directory;
  7. my @all_files = glob"*"; #Get All File Name(Except The .* Files)
  8. foreach(@all_files) {
  9. print "The Dir Has Files : $_\n";
  10. }
  11. }
  12. else {
  13. chdir "" or die "cannot chdir to $dir:$!"; #Go To Home Directory;
  14. }

chapter12.2.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Directory!\n";
  3. my $dir = <STDIN>;
  4. chomp $dir;
  5. if($dir) {
  6. chdir "$dir" or die "cannot chdir to $dir:$!"; #Go To $Dir Directory;
  7. my @all_files = glob".* *"; #Get All File Name(Except The .* Files)
  8. foreach(@all_files) {
  9. print "The Dir Has Files : $_\n";
  10. }
  11. }
  12. else {
  13. chdir "" or die "cannot chdir to $dir:$!"; #Go To Home Directory;
  14. }

chapter12.3.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Directory!\n";
  3. my $dir = <STDIN>;
  4. chomp $dir;
  5. if($dir) {
  6. opendir DIR,$dir or die "cannot chdir to $dir:$!"; #Go To $Dir Directory;
  7. foreach $file(readdir DIR) {
  8. print "The $dir Has Files : $file\n";
  9. }
  10. }
  11. else {
  12. chdir "" or die "cannot chdir to $dir:$!"; #Go To Home Directory;
  13. }

chapter12.4.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Files List,The Next Action Will Delete It!\n";
  3. chomp(@str = @ARGV); #Get The File List
  4. foreach(@str) {
  5. unlink $_ or warn"failed on $_:$!\n";
  6. }

chapter12.5.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Old File And New File Name!\n";
  3. my @file_list = @ARGV;
  4. my $old_file = $file_list[0];
  5. my $new_file = $file_list[1];
  6. if(-e $new_file) { #Detect NewFile Name Exist?
  7. warn "Can't raname $old_file to $new_file:$new_file exist!\n";
  8. }
  9. elsif(rename $old_file,$new_file) {
  10. }
  11. else {
  12. warn"rename $old_file to $new_file failed:$!\n";
  13. }

chapter12.6.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Directory!\n";
  3. my $dir = <STDIN>;
  4. chomp $dir;
  5. if($dir) {
  6. chdir "$dir" or die "cannot chdir to $dir:$!"; #Go To $Dir Directory;
  7. my @all_files = glob".* *"; #Get All File Name(Except The .* Files)
  8. foreach(@all_files) {
  9. print "The Dir Has Files : $_\n";
  10. }
  11. }
  12. else {
  13. chdir "" or die "cannot chdir to $dir:$!"; #Go To Home Directory;
  14. }

chapter12.7.pl

  1. #!/usr/bin/perl -w
  2. print"Please Input The Directory!\n";
  3. my $dir = <STDIN>;
  4. chomp $dir;
  5. if($dir) {
  6. chdir "$dir" or die "cannot chdir to $dir:$!"; #Go To $Dir Directory;
  7. my @all_files = glob".* *"; #Get All File Name(Except The .* Files)
  8. foreach(@all_files) {
  9. print "The Dir Has Files : $_\n";
  10. }
  11. }
  12. else {
  13. chdir "" or die "cannot chdir to $dir:$!"; #Go To Home Directory;
  14. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/582786
推荐阅读
相关标签
  

闽ICP备14008679号