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

37 lines
513 B
Perl
Raw Normal View History

2011-01-06 02:42:52 +00:00
#!/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)]);
2011-01-06 02:43:59 +00:00
open(my $fh2, '<', 'foo.txt');
2011-01-06 02:42:52 +00:00
2011-01-06 02:43:59 +00:00
while(my $line = <$fh2>) {
2011-01-06 02:42:52 +00:00
print $line;
}
2011-01-06 02:43:59 +00:00
my $fh3 = IO::File->new('foo.txt', 'r');
2011-01-06 02:42:52 +00:00
2011-01-06 02:43:59 +00:00
while(my $line = $fh3->getline()) {
2011-01-06 02:42:52 +00:00
print $line;
}
2011-01-06 02:43:59 +00:00
my $fh4 = IO::File->new('foo.txt', 'r');
my @lines4 = $fh4->getlines();
2011-01-06 02:42:52 +00:00
2011-01-06 02:43:59 +00:00
print @lines4;
print Data::Dumper->Dump([\@lines4], [qw(lines)]);
2011-01-06 02:42:52 +00:00
1;
__END__