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讀取文件內容的方法,可以根據實際需求選擇合適的方法進行文件內容讀取操作。