artist has asked for the wisdom of the Perl Monks concerning the following question:

Each subsequent change file has records mentioned to added/changed (L) or deleted (E)
change1
=======
L|Key1 Values
L|Key2 Values
L|Key3 Values

change2
=============
E|Key2 
L|Key4 values

change3
===============
L|Key4 values
E|Key7
L|Key8 values

change4
=============
L|Key7 values
L|Key9 values

I like to combine all the records but which are deleted. For deletion the record has to be deleted after it has been added/changed. I have around 300,000 records and efficient methods would be good. What is the best approach I can take?

Thank you,
artist

Replies are listed 'Best First'.
•Re: Change files mechanism
by merlyn (Sage) on Jun 24, 2003 at 17:54 UTC
    my %result; # preusume @ARGV is loaded with the changeNN files in the right order while (<>) { if (/^L\|(\S+)\s+(.*)/) { $result{$1} = $2; } elsif (/^E\|(\S+)/) { $result{$1} = undef; } else { warn "I don't understand: $_"; } } for (sort keys %result) { my $value = $result{$_}; if (defined $value) { # last thing was a change: print "L|$_ $value\n"; } else { # last thing was a delete: print "E|$_\n"; } }
    Untested, but I think I got the gist of your post.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.