2013-11-03 80 views
0

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

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

感谢

回答

2
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>; 
}; 
+0

作品比黄油更顺畅。非常感谢! – user2055171

+0

@ user2055171没问题 –