holli has asked for the wisdom of the Perl Monks concerning the following question:

I have the following module:
package SomeClass; use overload '<>' => \&diamond; sub diamond { my $self = shift; if ( wantarray ) { print "wants array\n"; return $self->handle->getlines; } else { print "wants scalar\n"; return $self->handle->getline; } } #... rest of code
that gets used like so:
my $f = SomeClass->new ("somefile"); my @f = <$f>; #here I get only one line instead of all
The problem: In the diamond function wantarray allways returns false, even when the diamond operator is in list context (like in the code above).

Is there anything I can do about this?


holli, /regexed monk/

Replies are listed 'Best First'.
Re: overload and wantarray
by Corion (Patriarch) on Feb 08, 2006 at 09:51 UTC

    Quoting perldoc overload unfortunately:

    BUGS Even in list context, the iterator is currently called o +nly once and with scalar context.