<tt><font size=2>Patrick Meidl <patrick@pantheon.at> wrote on 07/09/2012
03:12:07 PM:<br>
<br>
> Subject:</font></tt>
<br><tt><font size=2>> <br>
> Re: [Dbix-class] Problem getting data from resultset</font></tt>
<br><tt><font size=2>> <br>
> On Mon, Jul 09 2012, John Romkey <romkey@romkey.com> wrote:<br>
> <br>
> > On Jul 9, 2012, at 12:27 PM, Kenneth S Mclane wrote:<br>
> > > while (my @data = $sr->next)
{ <br>
> > <br>
> > The problem is this line of code.<br>
> <br>
> that's correct. this expression will always evaluate to TRUE, so the<br>
> loop won't finish and your code will croak after scalar($st->all)<br>
> iterations.<br>
> <br>
> > Try:<br>
> > <br>
> > while( my $data_scalar = $sr->next ) {<br>
> > my @data = $data_scalar->all;<br>
> <br>
> that's wrong, though. DBIx::Class::Resultset->next already returns
your<br>
> result row, so the code should be:<br>
> <br>
> while (my $data = $sr->next) {<br>
> # call accessors on your Accountv object<br>
> ...<br>
> }<br>
> <br>
> HTH<br>
> <br>
> patrick<br>
That did the trick Patrick, thank you. It seems I was way over complicating
it. Here is the working code for posterity:</font></tt>
<br>
<br><tt><font size=2>while ( my $data = $sr->next ) { </font></tt>
<br><tt><font size=2>
foreach my $field (@fields) {</font></tt>
<br><tt><font size=2>
my $val = $data;</font></tt>
<br><tt><font size=2>
foreach my $method
(split(/\./, $field)) {</font></tt>
<br><tt><font size=2>
$val = $val->$method;</font></tt>
<br><tt><font size=2>
}</font></tt>
<br><tt><font size=2>
$ws->write($row, $col, $val);</font></tt>
<br><tt><font size=2>
$col++;</font></tt>
<br><tt><font size=2>
}</font></tt>
<br><tt><font size=2> $col=0;</font></tt>
<br><tt><font size=2> $row++;</font></tt>
<br><tt><font size=2> }</font></tt>
<br><tt><font size=2>Now I am going to see if I can switch back to my regular
rs, but not on this one. I like the idea of walking down to the relationship
accessor so it is truly just one function that handles whatever you throw
at it.<br>
</font></tt>