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:
(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...)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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |