use XML::Simple; use Data::Dumper; use DBI; my $config = XMLin('c:\website\config.xml', forcearray => qr/table/ ) or die ("unable to open config file"); my ($access_database) = @{$config->{database}}; my ($results_directory) = @{$config->{results_directory}}; my $dsn = "driver=Microsoft Access Driver (*.mdb);dbq=$access_database"; my $driver = "dbi:ODBC:$dsn"; my $username = ''; my $password = ''; my $dbopt = { PrintError => 0, RaiseError => 0 }; open (LOG,'>c:\website\log.txt') or die "log $!"; my $dbh = DBI->connect($driver, $username, $password, $dbopt) or die "Error connecting: $DBI::errstr"; for $extract (@{$config->{extract}}) { my $results_file = $extract->{file}; my @results; my $ref; for $table (@{$extract->{table}}) { my $sql = "SELECT * FROM $table"; my $sth = $dbh->prepare($sql) or die "Unable to prepare ($sql): ", $dbh->errstr;; $sth->execute or die "Unable to execute ($sql): ", $sth->errstr; $ref->{$table} = $sth->fetchall_arrayref({}); } my $results = XMLout($ref,rootname=>'root', noattr=>1); print LOG Dumper $ref; print LOG $results; print LOG "\n\n"; local *RESXML; open (RESXML, ">$results_directory\\$results_file") or die ("Unable to open results file $results_directory\\$results_file: $!"); print RESXML $results; }