23 lines
480 B
Perl
23 lines
480 B
Perl
|
#!/usr/bin/perl
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
|
||
|
use Path::Tiny;
|
||
|
use autodie; # die if problem reading or writing a file
|
||
|
|
||
|
my $dir = path("/tmp"); # /tmp
|
||
|
|
||
|
my $file = $dir->child("file.txt");
|
||
|
|
||
|
# Read in the entire contents of a file
|
||
|
my $content = $file->slurp_utf8();
|
||
|
|
||
|
# openr_utf8() returns an IO::File object to read from
|
||
|
# with a UTF-8 decoding layer
|
||
|
my $file_handle = $file->openr_utf8();
|
||
|
|
||
|
# Read in line at a time
|
||
|
while( my $line = $file_handle->getline() ) {
|
||
|
print $line;
|
||
|
}
|