box-o-sand/PracticingPerl/cli/filehandles.pl

37 lines
513 B
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use IO::File;
use Data::Dumper;
open(my $fh, '<', 'foo.txt');
my @lines = <$fh>;
print Data::Dumper->Dump([\@lines], [qw(lines)]);
open(my $fh2, '<', 'foo.txt');
while(my $line = <$fh2>) {
print $line;
}
my $fh3 = IO::File->new('foo.txt', 'r');
while(my $line = $fh3->getline()) {
print $line;
}
my $fh4 = IO::File->new('foo.txt', 'r');
my @lines4 = $fh4->getlines();
print @lines4;
print Data::Dumper->Dump([\@lines4], [qw(lines)]);
1;
__END__