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

In reply to Re: Pipe dream by ruoso
in thread Pipe dream by tlm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.