All pastes #41026 Raw Edit

Stuff

public text v1 · immutable
#41026 ·published 2006-02-10 18:06 UTC
rendered paste body
sub get_news {
        my ( $dbh ) = @_;

        my $elements = ( );
        my $sth = $dbh->prepare( 'SELECT seq,title,url,tsstart,tsend,tsinsert FROM ticker ORDER BY tsinsert' ) or die "Failed to prepare SQL query: $dbh->errstr\n";
        $sth->execute;
        while ( my $row = $sth->fetchrow_hashref ) {
                $elements->{$row->{seq}} = {
                        title           =>      $row->{title},
                        url             =>      $row->{url},
                        tsstart         =>      $row->{tsstart},
                        tsend           =>      $row->{tsend},
                        tsinsert        =>      $row->{tsinsert},
                };
        }
        $sth->finish;

        return $elements;
}

my $news = get_news( $dbh );
foreach my $article ( keys( %{ $news } ) ) {
        use Data::Dumper;
        print Dumper $article;
}

# The above code always dumps out "$VAR1 = '1';" and then "Can't use string ("1") as a HASH ref while "strict refs" in use