in reply to Appending single record to CSV (or TDV, not too late to switch) - filling 13 fields from 13 files, one of which is split into array of 2 and I just need half of it...

and I'm thinking a CSV is good enough since I don't want to mess with SQL

Why not use both :) A simple demo for you

#!/usr/bin/perl use strict; use warnings; use DBD::CSV; # create db handle my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_ext => ".csv/r", RaiseError => 1, }) or die "Cannot connect: $DBI::errstr"; # create csv table if not exists my $table = 'mycache'; unless (-e $table.'.csv'){ $dbh->do ("CREATE TABLE $table ( uid char(100), line1 char(100), line2 char(100), line3 char(100), datetime char(20) ) "); } while (1) { # show records my $ar = $dbh->selectall_arrayref("SELECT uid FROM $table ORDER BY u +id"); print "$table.csv contains\n"; print " $_->[0]\n" for @$ar; print "\n"; # input new or existing record print "Input unique id (q to quit,c to clear) > "; chomp( my $input = <STDIN> ); exit if lc $input eq 'q'; # clear if (lc $input eq 'c'){ $dbh->do("DELETE FROM $table"); next; } # check existing or new my @f = $dbh->selectrow_array(" SELECT * FROM $table WHERE uid = ?",undef,$input); if (@f){ print "--\n $input EXISTS : @f \n--\n"; } else { my @f = ($input,'init1','init2','init3',scalar localtime); print "--\n $input NEW RECORD : @f \n--\n"; $dbh->do("INSERT INTO $table VALUES (?,?,?,?,?)",undef,@f); } }
poj
  • Comment on Re: Appending single record to CSV (or TDV, not too late to switch) - filling 13 fields from 13 files, one of which is split into array of 2 and I just need half of it...
  • Download Code