#!/usr/bin/perl -w use strict; use DBI; use DBD::Pg; use vars qw( @ImagesList ); my $dbh = DBI->connect("dbi:Pg:dbname='wonkaDB';host='192.168.1.1'", 'willy', 'pwd0ompa') ; if ( !$dbh ) { die "ERROR: Cannot connect to database.\n\n"; } print "connected to database.\n"; my $sql_cmd = "select image from media_state where attempted IS NULL limit 7 "; my $sth = $dbh->prepare($sql_cmd); $sth->execute() or die "Execute for media_state has failed.\n"; if ($sth->rows > 0 ) { my @fet_row = $sth->fetchrow_array; while ( @fet_row = $sth->fetchrow_array) { push(@ImagesList, $fet_row[0]); } } else { print("No images found in media_state table\n"); } $dbh->disconnect(); print join("\n",@ImagesList); exit;