in reply to flat file databases

Here's my go:

It's written in long hand with lots of variables to help (me) 'see' the method.

It loads the updates into a hash then loops through the data one line at a time making changes when the id matches and writing everything to a new file.

Any use?

#!/bin/perl5 use strict; use warnings; my %update; open (UPDATE, "update.txt") or die "Cannot open update.txt"; while (<UPDATE>){ chomp; # T00001 0123-12345 DD001 67 my @array = split '\t'; my $key = $array[0]; $update{$key} = [ @array[1..3] ] } close (UPDATE); open (MDF, 'mdfl.txt') or die "Cannot open update.txt"; open (OUT, '>', 'out.txt') or die "Cannot open out.txt"; while (<MDF>){ chomp; my $record = $_; my @fields = split '\t', $record; my $dmpiid = $fields[0]; if ( exists $update{$dmpiid} ){ my $curr = $fields[4]; my $update = $update{$dmpiid}[2]; $fields[3] = $curr; $fields[4] = $update; $record = join "\t", @fields; } print OUT $record, "\n"; } close (MDF); close (OUT);