use strict; use DBI; main(); exit; sub main { my $dbh = DBI->connect("dbi:Pg:", undef,undef, {RaiseError=>1,PrintError=>0}); my $table = "t"; $dbh->do("drop table $table") or die "die 1 - $!\n"; $dbh->do("create table t(c text)") or die "die 2 - $!\n"; my $routput = vacuum_analyze($dbh, $table); print "-- verbose output:\n"; print "-"x70, "\n"; print $$routput; print "-"x70, "\n"; } sub vacuum_analyze { my ($dbh, $table) = @_; my $output; open OLDERR, ">&STDERR"; close STDERR; open STDERR, ">", \$output or die "error opening a stderr (heh)\n"; $dbh->do("vacuum verbose analyze $table"); close STDERR; open STDERR, ">&OLDERR"; \$output; }