On 28/06/2011 18:28, Wernher Eksteen wrote:

Rob


use strict;
use warnings;

use Fcntl 'SEEK_SET';

my $format;

my $fh = *DATA;  # Replace with the appropriate 'open my $fh, '<', ... or die 
$!;

I wasn't quite sure at first what you meant by passing the file handle
<DATA>  in the while loop when $fh already existed,
so I changed the code slightly like this:


my $file = "file.txt";
open(my $fh, "<", $file) or die $!;

while (<$fh>) {

Works like a charm, thanks again!

That's exactly right. I meant that, if you were using an external file,
you only needed to replace the line

my $fh = *DATA;

with

open my $fh, '<', 'myfile.txt' or die $!;

which is pretty much what you have done. Unfortunately I made a mistake
and wrote

while (<DATA>) {

in the first loop, when it should be the same as the second loop which reads

while (<$fh>) {

My apologies.

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to