sdfouhdso888 发表于 2017-5-19 12:14:33

Perl Idioms Explained

http://www.perlmonks.org/index.pl?node_id=287647

open FILEHANDLE, 'somefile.txt' or die $!;
my $string = do { local $/; <FILEHANDLE> };

The above idiom is a consise way to "slurp" the entire contents of a file into a scalar without using a loop, such as:

open FILEHANDLE, 'somefile.txt' or die $!;
my $string = '';
while (<FILEHANDLE>) {
    $string .= $_;
}
页: [1]
查看完整版本: Perl Idioms Explained