open FILE, "<", "file.txt" or die "Cannot open file: $!";
while(<FILE>) {
print $_;
}
close FILE;
use File::Slurp;
my $content = read_file("file.txt");
print $content;
use IO::All;
my $content = io("file.txt")->slurp;
print $content;
use File::ReadBackwards;
my $bw = File::ReadBackwards->new("file.txt") or die "Failed to open file: $!";
while (my $line = $bw->readline) {
print $line;
}
这些是一些常见的Perl读取文件内容的方法,可以根据实际需求选择合适的方法进行文件内容读取操作。