in reply to Pipe dream

I recently got a similar problem. I needed to export all the data from a mdb (MS Access) file, but I don't use Windows, and don't have Access. So I found the mdbtools software that knows how to list the tables and how to export a table. So my idea was running
mdb-export -d , file.mdb tablename | gzip -9 -c > file.csv.gz
for each table of each file. But the problem was that some tables did have spaces in the name, then it was starting to be harder to do on plain shell, because it was splitting each part of the name of the table and using as a single name... So I decided to do it in Perl, and ended with the following code.
use IPC::Open2; use strict; opendir DIR, "."; my @bancos = grep { /.mdb$/ } readdir DIR; closedir DIR; foreach my $db (@bancos) { chomp $db; print "$db\n"; open TABLES, "mdb-tables -1 $db |" || die $!; my @tables = <TABLES>; close TABLES; my $dbdir = $db; $dbdir =~ s/\.mdb$//; mkdir $dbdir || die $!; foreach my $table (@tables) { chomp $table; open('MDBEXPOUT', "mdb-export -d , '$db' '$table' |") +|| die $!; $table =~ s/\W/_/g; open('OUTFILE', ">$dbdir/$table.csv.gz") || die $!; open2('>&OUTFILE', '<&MDBEXPOUT', "gzip", "-9", "-c") +|| die $!; wait; close MDBEXPOUT; close OUTFILE; print "$dbdir/$table\n"; } }
This code uses the pipes just like the shell would use... I was thinking in creating a module to make it easier to chain pipes like this, but, hmmmm... I'm not sure if it's a good idea...
daniel