in reply to Class::DBI error?

Don't know if this will solve your problem, but why are you doing:
for ( $thread ) {
$thread is one CDBI object with methods for each column. I don't think you're getting anything from looping on it. The code inside the loop should work without the 'for'.

Other than that it is hard to tell because it seems you are sending some data structures to your template and printing them there. I would try using Data::Dumper with warn to see if d_body and d_comment have what you think they have. Then run it through the template.

Replies are listed 'Best First'.
Re^2: Class::DBI error?
by stonecolddevin (Parson) on Jun 10, 2005 at 11:51 UTC
    I couldn't think of any other way to do it with what I had...I'm not really sure how to access my data through $thread like I am intending, how should I load up @d_body properly?
    meh.
      Given that $thread is a blessed object your code
      for ( $thread ) { my %data2; $data2{author} = $thread->author; $data2{date} = $thread->date; $data2{content} = $thread->content; push @d_body, \%data2; }
      is equivalent to
      push @d_body, {}; $d_body[-1]->{$_} = $thread->$_ for ("author", "date", "content");
      Still I don't see why you need @d_body. I would simply use
      my $d_body; $d_body->{$_} = $thread->$_ for ("author", "date", "content");
      and later in the code
      body=> [$d_body],


      holli, /regexed monk/
        Ahhh good thinking...wow that was simple
        meh.
      If the body is just a single record, you should be able to load that with the same code, just without the loop.

      I'm guessing the 0's you are seeing are empty arrays in scalar context, which would happen if you got no records back. You might want to put in a quick check after your retrieve to make sure you are getting a record back. If no records are retrieved, $thread will be undef. Actually, you'll want code to catch this anyway and handle it nicely.

        ahhh, so would you recommend wrapping it in eval{} and checking $@?
        UPDATE:Murr...should probably just check $thread for emptyness, right?
        meh.