#!/usr/bin/perl

my @dbs = _getAllDatabaseNames();
my $allInAString = join(' ', @dbs);
print "$allInAString\n";

sub _getAllDatabaseNames
{
    # First, query mysql to get the list of dbs.
    #

    my $dbsRaw = `/usr/bin/mysqlshow -uroot`;

    # Doesn't seem to be a way to get a simple list - so we have to parse the
    # names out from all the extra display frosting this command returns.
    #

    my @dbNames;
    my @lines = split("\n", $dbsRaw);
    
    for (my $i = 0; $i < (scalar @lines) - 1; $i++)
    {
        # First three lines are crap.
        #
        next if $i < 3;

        
        if ($lines[$i] =~ m/\| (\S*) (.*)\|/)
        {
            my $name = $1;
            push @dbNames, $1 if 'C_' eq substr($1, 0, 2);
        }
    }

    return @dbNames;
}

