Subject: | updated records are returned as strings, not objects |
Faber Fedor, an ABE.pm member, presented this problem to the list.
Basically, records from UPDATE are not returned properly from nextrec
The test is lame, but demonstrates the problem. The patch seems to fix it.
--
rjbs
Subject: | test_file.csv |
95709010,2
28176010,2
96087810,foo
62912R10,2
89840410,2
Subject: | post-update.t |
use strict;
use warnings;
use Test::More tests => 1;
use FlatFile;
my $MaxList = FlatFile->new(
FILE => "test_file.csv",
FIELDS => [qw(cusip value)],
MODE => "+<", # "<" for read-write access
RECSEP => "\n",
FIELDSEP => ","
);
foreach my $cusip ('95709010', '96087810', '62912R10', '89840410') {
my ($max) = $MaxList->lookup(cusip => "$cusip");
if ($max->cusip eq '96087810') {
$max->set_value("foo");
}
}
ok(1);
Subject: | flatfile.patch |
--- FlatFile.pm.old 2006-10-18 19:10:08.000000000 -0400
+++ FlatFile.pm 2006-10-18 19:08:59.000000000 -0400
@@ -430,15 +430,18 @@
$recno++ while $self->{DELETE}{$recno};
- # Someone may have done an in-memory update of the record
- # we just read. If so, discard the disk data and
- # return the in-memory version of the record instead.
- return $self->{UPDATE}{$recno}
- if exists $self->{UPDATE}{$recno};
-
- # if it wasn't updated, the continue processing
- # with the disk data
- my $line = $self->{file}[$recno];
+ my $line;
+ if (exists $self->{UPDATE}{$recno}) {
+ # Someone may have done an in-memory update of the record
+ # we just read. If so, discard the disk data and
+ # return the in-memory version of the record instead.
+ $line = $self->{UPDATE}{$recno}
+ } else {
+ # if it wasn't updated, the continue processing
+ # with the disk data
+ $line = $self->{file}[$recno];
+ }
+
return unless defined $line;
my @data = split $self->{FIELDSEP}, $line, -1;
$self->{recno} = $recno+1;