Re: search always returns an iterator
[prev]
[thread]
[next]
[Date index for 2005/05/06]
I tried again putting () to force list context. Same thing, an iterator.
I traced through the code in cDBI didn't see it check for list context
just went straight thru to iterator.
On Thu, 5 May 2005, Cees Hek wrote:
> On 5/5/05, Dana Hudes <dhudes@xxxxxx.xxxx> wrote:
> > Despite calling the search method in a list context I always get an
> > iterator back. I don't want this, its inefficient and annoying: I expect
> > no more than perhaps 2 or 3 records and usually only the one.
> >
> > @foo = Data::Foo->search(%bar);
> >
> > and you only get the one element in @foo which is an object of
> > Class::DBI::Iterator .
>
> Are you sure you are not forcing scalar context on the search method?
>
> @foo = Data::Foo->search(%bar) || die "I just forced scalar context
> and an Iterator will be returned";
>
> In the above you need to use 'or' instead of '||' which has lower
> precedence and won't clobber your array context.
>
> Cheers,
>
> Cees
>