Jeff,

Thanks again for your time and assistance thus far with helping me to visualise this. :)

Another thought has occurred to me as well, with regards to Subscriber::DB :

one of the client requests is to be able to extract the database, or portions of the database to a CSV style format.

I'd LIKE to be able to (I think) inherit from Subscriber::DB somehow for a Subscriber::DB::CSV such that I can take the filtered request and retrieve/output CSV-formatted records from the database..

I've already produced the code to do so in another command-line based script (mysql2csv), thusly:


#!/usr/bin/perl -l
use warnings;
use strict;
use DBI;
use Fatal qw[open close];

my ($db, $user, $pass, $dbitable) =
   qw/ database username password table /;
my $mysql_dbh = DBI->connect("dbi:mysql:database=$db:host=localhost", $user, $pass, {RaiseError => 1, PrintError => 1});

my $sth = $mysql_dbh->prepare(
    "SELECT * from $dbitable ORDER BY lastname,email;"
);
$sth->execute();
print $sth->rows, " rows found.\n";

rename 'mailerdata.csv', 'mailerdata.csv.bak'
        if -e 'mailerdata.csv' && -f _ && -T _;
open my $csvfh, ">", 'mailerdata.csv';

print $csvfh join ",", map { qq{"$_"} } @{$sth->{'NAME'}};

no warnings 'uninitialized';
while (my $db_row = $sth->fetchrow_arrayref) {
        print $csvfh join ",", map {  qq{"$_"}  } @{$db_row};
}

close $csvfh;
__END__

I have a *fair* idea of how I'd modularize this, but I'm still unsure about Subscriber::DB (as per my recent two responses to your post to the list) as to whether I'd have Subscriber::DB::filter() return an $sth, or embed the $sth inside the object and use further methods to loop over the results. (the end result being I'm unsure as of yet how to go on.) :)

Your thoughts?

-scott

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to