Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: dbf_dump to apply to multiple files in a directory

by stefbv (Curate)
on Aug 03, 2014 at 13:44 UTC ( #1096059=note: print w/replies, xml ) Need Help??


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).

Replies are listed 'Best First'.
Re^2: dbf_dump to apply to multiple files in a directory
by solanum (Initiate) on Aug 03, 2014 at 19:16 UTC

    I will also try this out. But it will probably take me a lil longer to go through the logic. Thank you for all your help!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1096059]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-10-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (77 votes). Check out past polls.

    Notices?