http://qs321.pair.com?node_id=1096059


in reply to dbf_dump to apply to multiple files in a directory

In the spirit of TIMTOWTDI, there is another way, you can use the 'dump_records' sub from the 'XBase' module directly.

Unfortunately there is no parameter in that sub for the output file, so we have to use 'select' to redirect the output to our CSV file.

use strict; use warnings; use XBase; my $dbf_file = shift; die "Usage dbf2csv <dbf-file>" unless -f $dbf_file; dbf_dump($dbf_file, fs => ','); # defaults: rs=>"\n", fs=>':', 'undef' +=>'' sub dbf_dump { my ($dbf, %opts) = @_; my $csv = "$dbf.csv"; open my $fh, '>', $csv or die "Can't write to file ", $csv, ": $!" +; select $fh; dump_records($dbf, %opts); select STDOUT; close $fh; } sub dump_records { my ($name, %opts) = @_; my $table = XBase->new($name) or die XBase->errstr; $table->dump_records(%opts); $table->close; }

Now you can add the two subs to your script and call dbf_dump like in the example.

(The script from DBD::XBase is named 'dbfdump', without the underscore).