in reply to File handles in an object
I think what's happening is:use strict; package MyFile; ## Constructor ## sub new { my $self = {}; bless $self; } sub open_file { my $self = shift; open(FH, "textfile") || die "can't open file"; $self->{FH} = \*FH; } sub read_file { my $self = shift; my $line; my $f = $self->{FH}; while (defined ($line = <$f>)) { print "Line from file is: $line\n"; } } my $my_object = new(); $my_object->open_file(); $my_object->read_file();
is being parsed like<$self->{FH}>
That is, a file handle specification, with a subscript outside the <>'s, followed by a >, which is a syntax error.<$self-> {FH} >
Alan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: File handles in an object
by visnu (Sexton) on Jul 11, 2000 at 23:01 UTC |