playing with file handles
This commit is contained in:
parent
760ded693b
commit
d690d1b0bd
36
cli/filehandles.pl
Normal file
36
cli/filehandles.pl
Normal 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
6
cli/foo.txt
Normal file
@ -0,0 +1,6 @@
|
||||
these
|
||||
runes
|
||||
are
|
||||
dusty
|
||||
sir
|
||||
?
|
Loading…
Reference in New Issue
Block a user