#!/usr/local/bin/perl -w

# $Id: data_convert,v 1.1.2.1 2004/04/19 17:29:05 dgrant Exp $

use strict;
use lib $ENV{'SBLIBPERL'};


use Data::All;
use Data::Dumper;

my $DEBUG = 10;
#BEGIN { $SIG{'__WARN__'} = \&__warn; }



sub main()
{
    my $dsn1     = 'DBI:mysql:database=mysql;host=YOURHOST;port=3306';
    my $dsn2     = 'DBI:mysql:database=test;host=YOURHOST;port=3306';
    my $query1   = 'SELECT `Host`, `User`, `Password` FROM user';
    my $query2   = 'INSERT INTO users2 (`Password`, `User`, `Host`) VALUES(?,?,?)';
    
    my %db1 = 
    (   path        => [$dsn1, 'user', '7i75', $query1],
        ioconf      => ['db', 'r' ]
    );
    my %db2 = 
    (   path        => [$dsn2, 'user', '7i75', $query2],
        ioconf      => ['db', 'w' ],
        fields      => ['Password', 'User', 'Host']
    );
    
    my %file1 = 
    (
        path        => 'examples/test.tab',
        #profile     => 'tab',
        format      => ['delim', "\n", "\t", '"', '\\'],
        ioconf      => ['plain', 'r', 1],
        #moniker     => 'asshole'
    );
    
    my %file2 = 
    (
        path        => 'converted.csv',
        ioconf      => ['plain', 'w'],
        format      => ['delim', "\n", ',', '"', '\\'],
    );
    
    my %file3 = 
    (
        path        => 'converted.fixed',
        ioconf      => ['plain', 'w', 1],
        format      => ['fixed', "\n", [24,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13]],
    );
    
    my %file4 = 
    (
        path        => 'converted2.csv',
        ioconf      => ['plain', 'w'],
        format      => ['delim', "\n", ',', '"', '\\'],
        fields      => ['Password', 'User', 'Host'],
    );
    
    
    
    #   Create an instance of Data::All for database data
    my $input1 = Data::All->new(%file1);
    
    #   Open the connection. Nothing happens until you tell it to. 
    $input1->open();
    #   $rec now contains an arrayref of hashrefs for the data defined in %db.
    #   $rec2 is identical to $rec. collection() is a shortcut.
    my $rec  = $input1->read();
    #my $rec2 = collection(\%file1);
    #print Dumper($rec2);
    #   The data defined in %db is now saved in the data profile of %file1
    #   This is like transport with the flitering
    $input1->convert(\%file3); 

}

sub __warn
{ 
    return;
    return unless($DEBUG);
    warn($_[0]), return if ($_[0] !~ /^\d/);
    warn substr($_[0], 1) if (substr($_[0], 0, 1) <= $DEBUG);
}


main();

    














__END__


        path        => ['converted.csv'],
        io          =>
        {
            type    => 'plain',
            access  => 'r'
        },
        format      =>
        {
            type    => 'delim',
            break   => "\n",
            delim   => ',',
            quote   => '"',
            escape  => '\\'
        }
    
    