[CDBI] cdbi objects evaluating as false

Matt S Trout dbix-class at trout.me.uk
Sat Nov 25 17:36:39 GMT 2006


On 25 Nov 2006, at 17:20, Aaron Trevena wrote:

> Hi all,
>
> I'm finding that when I do :
>
> while (my $object = $iterator->next) {
> ..
> }
>
> .. the loop never happens because 'my $object = $iterator->next' seems
> to be false.
>
> instead I have to do :
>
> my $object = $iterator->next();
> while (defined $object && $object->pk) {
>  . . .
>  $object = $iterator->next();
> }

What's wrong with

while (defined (my $object = $iterator->next)) {
   ...
}

?

In general you want to do that anyway with stuff that might stringify  
just in case the stringification turns out to be an expensive  
operation or whatever ...
-- 
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +





More information about the ClassDBI mailing list