Try taking the CSV file and cutting it in halves
Gah! One could probably find the problem with much, much less effort if one weren't pathologically opposed to the use of debuggers. q-:
But seriously, in this case I'd build a hash of record IDs returned by Text::CSV and then use the method that "works" and report the records where Text::CSV starts/stop seeing records:
#!/usr/bin/perl
use DBI;
tdbh = DBI->connect("DBI:CSV:")
or die "Cannot connect: " . $DBI::errstr;
my $sth = $tdbh->prepare("select * from ofphl");
$sth->execute();
my %dbi;
my $rec;
while( $rec= $sth->fetch() ) {
$dbi{$rec->{id_field_name}}++;
};
open FILE, "< file.csv"
or die "Can't read file.csv: $!\n";
my $has= 1;
$|= 1;
while( <FILE> ) {
my $id= ( split(/,/) )[0]; # Assuming ID is first field;
if( !$has != !$dbi{$id} ) {
print "DBI ", ( $has ? "stopped" : "started" ),
" at record $id.\n";
$has= !$has;
}
}
Note that you might need to concatenate more than one field if there isn't a unique ID field.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|