playing with file handles

This commit is contained in:
Dan Buch 2011-01-05 21:42:52 -05:00
parent 760ded693b
commit d690d1b0bd
2 changed files with 42 additions and 0 deletions

36
cli/filehandles.pl Normal file
View File

@ -0,0 +1,36 @@
#!/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__

6
cli/foo.txt Normal file
View File

@ -0,0 +1,6 @@
these
runes
are
dusty
sir
?