in reply to enforcing list context

You'll have to return an array if you want scalar context to return the size. Otherwise, use wantarray and do something like:
sub value { my ($self) = @_; return wantarray ? ($self->{first}, $self->{rest} ? $self->{rest}->value : ()) : 1 + ($self->{rest} && $self->{rest}->value) }

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Replies are listed 'Best First'.
Re^2: enforcing list context
by billh (Pilgrim) on Apr 26, 2006 at 12:53 UTC
    yes, that's probably the best solution.
    My first solution is poorer because of the temp @value, and the second because of the extra ref/deref on each call.