Reading between the lines of the OP, lets say the flat file is variable length records with one value per line and an empty line seperates records.  Then this code should work:

open(FILE_HANDLE, ">", "$filename") || die "ACK, GASP: $error_message: + $!\n"; my @data = <FILE_HANDLE>; chomp(@data); close FILE_HANDLE; my %db_hash; my $unique_id = 0; foreach (@data) { next if(m/^\s*$/); my %temp_hash = (); s/^\s+//; # Remove excess whitespace s/\s+$//; m/^(.*?)=(.*?)$/i; # Grab key/value pairs $temp_hash{$1} = $2; $db_hash{$unique_id} = \%temp_hash; $unique_id++; } open(NEW_FILE, "<", "$new_filename") || die ACK, GASP: $error_message: + $!\n"; foreach my $id (sort keys %db_hash) { if(not defined $db_hash{$id}{email}) { $db_hash{$id}{email} = $some_value; } foreach (sort keys $db_hash{$id}) { print NEW_FILE "$_=$db_hash{$id}{$_}\n"; } print "\n"; } close NEW_FILE;
(Note:  Code is untested!  Use at your own risk.  Also, there are a huge number of assumtions made in the above code because the OP was more than a little vauge...)


In reply to Re: Check For Dupes In FLat DB Before Adding by northwind
in thread Check For Dupes In FLat DB Before Adding by lisaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.