[Dbix-class] Problem getting data from resultset

Kenneth S Mclane ksmclane at us.ibm.com
Mon Jul 9 16:27:22 GMT 2012


Patrick Meidl <patrick at pantheon.at> wrote on 07/06/2012 04:00:09 PM:
> 
> if you posted your code it would be easier to help debug it...
> 
>     patrick
> 
Here is my current code, which wants to go to the 86th row on a RS with 85 
rows.

        my $sr = $c->model('ORANGES::Accountv')->search_rs({}, {});
        my $wb = 
Spreadsheet::WriteExcel->new('/opt/catalyst/dbms/lib/dbms/output/output.xls');
        my $ws = $wb->add_worksheet('Output');
        my $col = 0; my $row = 0;
        my @fields = qw/department_code account_code account_name 
account_policy num_servers num_subsystems percent_complete 
percent_compliant account_status/;
        foreach my $field (@fields) {
                $ws->write($row, $col, $field);

                $col++;
        }
        $col=0;
        $row++;
        my $d = 1;
        my $e = 1;
        while (my @data = $sr->next) {
                foreach my $data (@data) {
                        foreach my $field (@fields) {
                                my $val = $data;
                                foreach my $method (split(/\./, $field)) {
                                        $val = $val->$method;
                                }
                        $ws->write($row, $col, $val);
                        $col++;
                        }
                $col=0;
                $e++;
                } 
                $row++;
                $d++;
        }
I switched to a custom RS that removed the problem of having to dig down 
and dereference, plus allowed me to create the account_status column 
before rather than after. Long story.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120709/51b344e0/attachment.htm


More information about the DBIx-Class mailing list