use strict; use warnings; use DBI; use File::Basename; my @stuff; my $file = 'sfoct01.txt'; my $table = (fileparse($file,'.txt'))[0]; my $dbh = DBI->connect( "DBI:CSV:f_dir=.;csv_eol=\n;csv_sep_char=,;", {RaiseError=>1}, ); $dbh->{csv_tables}->{$table} = { file => $file, col_names => [qw(account amount)], }; my $sth = $dbh->prepare(" SELECT account,amount FROM $table ORDER BY account "); $sth->execute; while (my ($account,$amount) = $sth->fetchrow_array()) { @stuff = ($account, $amount, 10, 10 - $amount); write; } format STDOUT_TOP = +-----------------------------------------------------------------+ | Monthly Recap | |----------------------------+----------+-----------+-------------+ |Account | Prior | Current | Difference | |----------------------------+----------+-----------+-------------+ . format STDOUT = |@<<<<<<<<<<<<<<<<<<<<<<<<<<<|@#####.## | @#####.## | @#####.## | @stuff |----------------------------+----------+-----------+-------------+ . __END__ yields: +-----------------------------------------------------------------+ | Monthly Recap | |----------------------------+----------+-----------+-------------+ |Account | Prior | Current | Difference | |----------------------------+----------+-----------+-------------+ |Bam bam | 5.00 | 10.00 | 5.00 | |----------------------------+----------+-----------+-------------+ |Betty | 300.00 | 10.00 | -290.00 | |----------------------------+----------+-----------+-------------+ |Wilma | 200.00 | 10.00 | -190.00 | |----------------------------+----------+-----------+-------------+ |barney | 30.00 | 10.00 | -20.00 | |----------------------------+----------+-----------+-------------+ |fred | 10.00 | 10.00 | 0.00 | |----------------------------+----------+-----------+-------------+