Re: [SLUG] search and replace

From: Levi Bard (levi@bard.sytes.net)
Date: Tue Aug 12 2003 - 22:59:07 EDT


> Perl, yes, and here's how I'd do it:
>
> Read the entire update file into memory. Open the main file and scan it
> in line by line. At each line, compare its "key" to the update file's
> lines (in memory). On a match, output the update line. Else, output the
> original line. Close all the files. Kill the original file, and rename
> the old file to the new file.
>
> The actual code is left as an exercise for the reader. ;-}

Not too bad, assuming the update file is fairly small. Here's my alternative solution - read the main file into a hash keyed by the first field, read in the update data, replacing the old values in the hash, then sort/print.

I'll attach my code, assuming the post doesn't get dumped for an 802B text attachment.

Levi



-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 16:39:24 EDT