<commit_before>use strict;
use warnings;

my $mdb_name = "flanders.mdb";
my $outdb_name = "flanders.db";

# Generate the schema
print "Generating schema...\n";
`mdb-schema $mdb_name | sqlite3 $outdb_name`;
print "Schema has been generated.\n";

# Copy data from tables
my @tables = split "\n", `mdb-tables -1 $mdb_name`;
for (@tables) {
    print "Exporting data from table $_...\n";
    `mdb-export $mdb_name $_ >> out.csv`;
    `sqlite3 -separator "," $outdb_name '.import out.csv $_'`;
    `rm out.csv`;
}
print "$mdb_name has been exported to $outdb_name.\n";<commit_msg>Add command line options to designate input/output files, and add prompt for overwriting an existing database<commit_after>#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Long;

my $auto_overwrite = '';
my $help = '';
GetOptions ('auto-overwrite!' => \$auto_overwrite,
            'help!' => \$help);

# Make sure we have two arguments
my $num_args = $#ARGV + 1;
if ($num_args != 2 || $help) {
    print "Wrong number of arguments (got $num_args, need 2)\n" 
      if (!$help);
    print "Usage: mdb_to_sqlite.pl [--auto-overwrite] MDB_FILE OUT_FILE\n";
    exit;
}
my ($mdb_name, $outdb_name) = @ARGV;

# If the file exists...
if (-e $outdb_name) {
    if ($auto_overwrite) {
        print "$outdb_name will be overwritten.\n";
        `rm $outdb_name`;
    }
    else {
        my $overwrite;

        # Ask user whether they want to overwrite the file
        # Keep looping until we get a valid answer
        while (1) {
            print "$outdb_name exists! Overwrite? (Y/N) ";
            $overwrite = <STDIN>;

            last if $overwrite =~ m/^(y|n)$/i;

            print "Didn't understand input...\n";
        }

        if ($overwrite =~ m/^y$/i) {
            print "$outdb_name will be overwritten.\n";
            `rm $outdb_name`;
        }
        elsif ($overwrite =~ m/^n$/i) {
            print "Aborting...\n";
            exit;
        }
    }
}

# Generate the schema, initializing the database
print "Generating schema...\n";
`mdb-schema $mdb_name | sqlite3 $outdb_name`;
print "Schema has been generated.\n";

# Export the data from each table
my @tables = split "\n", `mdb-tables -1 $mdb_name`;
for (@tables) {
    print "Exporting data from table $_...\n";
    `mdb-export $mdb_name $_ >> out.csv`;
    `sqlite3 -separator "," $outdb_name '.import out.csv $_'`;
    `rm out.csv`;
}
print "$mdb_name has been exported to $outdb_name.\n";
{'fraction_non_alphanumeric': 0.15415986949429036, 'fraction_numerical': 0.004078303425774877, 'mean_word_length': 2.6776611694152925, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '181915', 'n_tokens_mistral': 880, 'n_tokens_neox': 846, 'n_words': 253}