zoukankan      html  css  js  c++  java
  • 第五章答案

    #! /usr/bin/perl
    use strict;
    use warnings;

    =head1
    print " ----------------------------------ch_5_Q1_-------------------------- ";
    #print reverse <>;
    print " ----------------------------------_-------------------------- ";
    select STDIN;
    my @single_quotation = <>;
    print @single_quotation;
    print " ----------------------------------ch_5_Q1_-------------------------- ";
    =cut

    print " ----------------------------------ch_5_Q2_-------------------------- ";
    print "What column width would you like?, please input:";
    chomp(my $width = <STDIN>);
    print "Enter some lines, then press Ctrl-D: "; # or Ctrl-z
    my @underscore;
    chomp(@underscore = <STDIN>);
    #@underscore = <STDIN>;
    #print " "."1234567890"x7,"12345 ";
    print " "."1234567890"x (($width + 9)/10),"12345 ";

    =head1
    foreach(@underscore){
        #print "$_"." ";
        printf "%20s ", $_;
    }
    =cut

    my $semicolons = "%${width}s " x @underscore;
    printf "$semicolons", @underscore;
    print " ----------------------------------ch_5_Q2_-------------------------- ";







    自己的答案

    #! /usr/bin/perl
    use strict;
    use warnings;

    print " -------------------------------------tac_----------------------- ";
    #foreach(@ARGV){
        my $file_number = $#ARGV;
        print $file_number;
        print " ";
        foreach( reverse(0..$file_number) ){

           #foreach(<$ARGV[$_]>){
           #     print $_;
           #}
            print "$ARGV[$_] ";
            my @lines;
            open TEMPFD, "< $ARGV[$_]" ;
            #@lines = <$ARGV[$_]>;
            @lines = <TEMPFD>;
            #print @lines;
            my $file_lines = $#lines;
           foreach( reverse(0..$file_lines) ){
                print $lines[$_];
           }
           close TEMPFD;
        }
    #}
    print " -------------------------------------tac_----------------------- ";

























    print " -------------------------------------_----------------------- ";














    print " ----------------------------------_-------------------------- ";

  • 相关阅读:
    Python 文件的输入与输出
    php获取客户端真实ip
    php设计模式(3)-观察者模式
    php设计模式(2)-单例模式
    php设计模式(1)-工厂模式
    设计模式
    设计模式-观察者模式
    include和require的区别
    php分页类
    反向Ajax,第5部分:事件驱动的Web开发
  • 原文地址:https://www.cnblogs.com/books2read/p/11004044.html
Copyright © 2011-2022 走看看