Re: CDBI::Iterator->first moves it's index pointer

[prev] [thread] [next] [Date index for 2004/11/10]

From: Tony Bowden
Subject: Re: CDBI::Iterator->first moves it's index pointer
Date: 19:31 on 10 Nov 2004
On Wed, Nov 10, 2004 at 06:23:15PM +0100, Rhesa Rozendaal wrote:
> It turns out that "first" does this:
> 	my $self = shift;
> 	$self->reset;
> 	return $self->next;
> In other words, it moves the iterator to the next element, returning the 
> first. 

Not quite. It moves the iterator to before the start of the list, and
then returns the 'next' one (which is, by definition, the first one.

> I expected it to return the first element, and not move its index 
> pointer.

That would be weird.

Consider:

	my $it = run_some_search();

  print $it->first;
  print $it->next;
  print $it->first;
  print $it->next;

Would you really expect this to print 1, 2, 1, 3? I'd say most people
would expect 1, 2, 1, 2.

I'm open to opinions here.

Tony

CDBI::Iterator->first moves it's index pointer
Rhesa Rozendaal 17:23 on 10 Nov 2004

Re: CDBI::Iterator->first moves it's index pointer
Tony Bowden 19:31 on 10 Nov 2004

Re: CDBI::Iterator->first moves it's index pointer
Rhesa Rozendaal 21:31 on 10 Nov 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52