in reply to Re: Class::DBI error?
in thread Class::DBI error?

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.

Replies are listed 'Best First'.
Re^3: Class::DBI error?
by holli (Abbot) on Jun 10, 2005 at 12:26 UTC
    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.
Re^3: Class::DBI error?
by cbrandtbuffalo (Deacon) on Jun 10, 2005 at 12:06 UTC
    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.
        No, I think a simple 'if' should do the trick:
        if( not $thread){ # Send a message to the user in some way... print"No record found for thread number: $id"; # Get out of the structure in some way... exit; }