From d690d1b0bd7b9caaeaa9f980df607e14b473b861 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 5 Jan 2011 21:42:52 -0500 Subject: [PATCH] playing with file handles --- cli/filehandles.pl | 36 ++++++++++++++++++++++++++++++++++++ cli/foo.txt | 6 ++++++ 2 files changed, 42 insertions(+) create mode 100644 cli/filehandles.pl create mode 100644 cli/foo.txt diff --git a/cli/filehandles.pl b/cli/filehandles.pl new file mode 100644 index 0000000..15372fa --- /dev/null +++ b/cli/filehandles.pl @@ -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__ diff --git a/cli/foo.txt b/cli/foo.txt new file mode 100644 index 0000000..ec5e80f --- /dev/null +++ b/cli/foo.txt @@ -0,0 +1,6 @@ +these +runes +are +dusty +sir +?