[mplspm]: overloading <>

James.FitzGibbon James.FitzGibbon at target.com
Thu May 2 16:57:26 CDT 2002


Does anyone have experience overloading iterators?  I'm having a hell of a
time
trying to create a subclass of IO::File.  I started out with just getline
overridden.
That works fine for this:

my $fh = new IO::File::Derived;
while( $_ = $fh->getline ) {
	print;
}

But now I want to be able to do this for simplicity:

my $fh = new IO::File::Derived;
while( <$fh> ) {
	print;
}

When I overload <> to point to my class's getline method, I get stuck in a
loop.
The IO::File::Derived class does conditional evaluation of it's input, so
several
lines may be read from the file and discarded before a single line gets
returned to
the caller.  As such, I need to call $self->SUPER::getline from inside of my
getline
method.

The problem is that IO::Handle::getline does this:

return scalar <$this>

Which gets dispatched to my getline, which calls $self->SUPER::getline,
which calls my
getline ad infinitum.

Any ideas?  I'll refrain from posting the whole class unless someone wants
to go over
the details with me...

Thanks.

-- 
j.
 
James FitzGibbon                     
Consultant, Ajilon Services, TTS-3D at TPN4H 
james.fitzgibbon at target.com 
voice/fax 612-761-6121/4277
 


--------------------------------------------------
Minneapolis Perl Mongers mailing list

To unsubscribe, send mail to majordomo at pm.org
with "unsubscribe mpls" in the body of the message.



More information about the Mpls-pm mailing list