#!/usr/bin/perl
# w6.3.pl:  DELETE info from flat database.  
# To try this   cp ~horn/public_html/tc392/perl/w6.2.fdb temp.fdb 
# Usage:  w6.3.pl Johnson
# If a Johnson exists, his record will be eliminated

undef($/);			#no boundaries; data read as 1 string
open (FH, "temp.fdb");
$contents = <FH>;
close (FH);

#Create new array of records
@records = split(/^Last:/m, $contents); 
shift(@records);
foreach (@records){
   $_ = "Last:" . $_; 				#Restore Last;
   if ($_ !~ /^Last: \s*$ARGV[0]/m){ 		#Searching for last name
      @new_records = (@new_records, $_); 	#Create new array of records   
   }
}

#Replace database with new array
open (OUT, ">temp.fdb");		# Now open db for write.
foreach (@new_records){
   print (OUT "$_");
}
close (<OUT>);
