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
504 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 $fh, '<', 'foo.txt');
while(my $line = <$fh>) {
print $line;
}
my $fh = IO::File->new('foo.txt', 'r');
while(my $line = $fh->getline()) {
print $line;
}
my $fh = IO::File->new('foo.txt', 'r');
my @lines = $fh->getlines();
print @lines;
print Data::Dumper->Dump([\@lines], [qw(lines)]);
1;
__END__