10 de enero de 2010

PostgreSQL&Perl. Asignar datos de una consulta a matriz bidimensional


Un ejemplo:

#!/usr/bin/perl -w

use DBI;
use strict;

my $dbh = DBI->connect("dbi:Pg:dbname=ipuniverse",'user');
my $sth = $dbh->prepare("SELECT scann2.ip,scann2.pais,scann2.ciudad FROM scann2 LIMIT 5");

$sth->execute;

my $table = $sth->fetchall_arrayref;
my ($lin, $col);

for $lin ( 0 .. $#{$table} ) {
for $col ( 0 .. $#{$table->[$lin]} ) {
print "$table->[$lin][$col]\t";
}
print "\n";
}

$sth->finish;
$dbh->disconnect;
exit;


Ref:
Manual de referencia de DBI/DBD

No hay comentarios:

Publicar un comentario