use strict; use warnings; use DBI; use Data::Dumper; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( qw(log Tab data.txt), { col_names => 'date,user,agency,url,garbage,success,module' }, 'ad_catalog', ); my %pass = fetch_rows('pass'); my %fail = fetch_rows('fail'); print join("\t",qw(Agency Url Pass Fail Module)),"\n"; # loop thru @pass, try to fetch from @fail # i'll let you decide how to sort ;) for my $key (keys %pass) { my ($agency,$url,$module) = split(':',$key); my $pass = $pass{$key}; my $fail = $fail{$key} || 0; print join("\t",$agency,$url,$pass,$fail,$module),"\n"; } # trick here is to append agency, url, and module # so they are treated as one unique entity # too bad you can't use unique with AnyDBD ... # watch out, i use a colon as the delimter - YMMV sub fetch_rows { my $success = shift; my $sth = $dbh->prepare(' SELECT agency, url, module FROM log WHERE success = ? '); $sth->execute($success); my %hash; $hash{ join(':', $_->{agency}, $_->{url}, $_->{module}) }++ while $_ = $sth->fetchrow_hashref; return %hash; }