You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/cli/filehandles.pl

37 lines
513 B

#!/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__