[Dbix-class] Problem getting data from resultset

John Romkey romkey at romkey.com
Mon Jul 9 17:25:31 GMT 2012


On Jul 9, 2012, at 1:09 PM, Kenneth S Mclane wrote:
> John Romkey <romkey at romkey.com> wrote on 07/09/2012 11:48:34 AM:
> 
> > Re: [Dbix-class] Problem getting data from resultset 
> > 
> > On Jul 9, 2012, at 12:27 PM, Kenneth S Mclane wrote: 
> >         while (my @data = $sr->next) { 
> > 
> > The problem is this line of code. @data in a scalar context will 
> > evaluate to the index of the last element of the array (-1 if the 
> > array is empty) (assuming you haven't changed the index of the first
> > element of arrays). The loop will succeed even when $sr->next 
> > returns undefined. 
> > 
> > Try: 
> > 
> > while( my $data_scalar = $sr->next )  { 
> >       my @data = $data_scalar->all; 
> > 
> > instead 
> > 
> 
> I actually changed it to this: my @data = $sr->all; I think this is equivalent isn't it? This does not give me any errors, but only outputs one row to the file.

$sr is your resultset

$sr->next gives you the next row

$sr->all gives you all records

http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#all

in my example $data_scalar->all will return the values of all the columns in that row - very different from getting all the rows in the resultset
	- john romkey
	http://romkey.com/



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120709/6a7c8de1/attachment.htm


More information about the DBIx-Class mailing list