in reply to parsing $sth-{NAMES}

Check out perldoc DBI
Look for $sth->fetchrow_hashref
This will put every row into a hash with the column-names as keys.