Perl Idioms Explained
http://www.perlmonks.org/index.pl?node_id=287647open 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]