【问题标题】:Perl file readingPerl 文件读取
【发布时间】:2013-11-14 07:57:42
【问题描述】:

我现在正在学习 perl/CGI,并试图弄清楚如何在 perl 中读取文件。我让我的程序将每一行读入新变量。

现在我希望我的程序将第一行读入变量 $first_line 并将文件的其余部分存储到另一个变量 $rest 中。我该怎么做?

谢谢

【问题讨论】:

    标签: perl file cgi


    【解决方案1】:
    my $first_line = <$file_handle>;
    
    # read rest of the file only if first line was read
    my $rest = defined($first_line) && do {
      # input record separator set to undef (slurp mode)
      local $/;
      <$file_handle>;
    };
    

    【讨论】:

    • @user2055171 没问题
    猜你喜欢
    • 2017-08-05
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 2019-11-19
    相关资源
    最近更新 更多