### check the MATLAB tutorial for stuff.

@htref = ();
@htdef = ();
@Htref = ();
@Htdef = ();

@matches = qw(htref htdef Htref Htdef);

 for $file (<*.tex>) {
   ## filter out bad ones
   next if $file eq '_region_.tex';
   open (INFILE,$file) || die "can't open $file\n";
   while (<INFILE>) {
     chop;
     $line = $_;
     foreach $match (@matches) {
       if ($line =~ /\\$match\{([a-zA-Z ]*)\}/) {
 	push(@{$match},$1);
       }
     }
   }
 }

 print "htdef = @htdef\n";
 print "htref = @htref\n";


@temp = &set_int(\@htdef,\@htref);
print "intersetcion = @temp\n";

@temp = &set_diff(\@htref,\@htdef);
print "difference = @temp\n";


sub set_int {
  ($a,$b) = @_;
  @intersect = ();

  foreach (@{$a}) {
    $a{$_}=$_;
  }
  foreach (@{$b}) {
    $b{$_}=$_;
  }
  foreach (keys %a) {
    push (@intersect, $_) if defined $b{$_};
  }
  return @intersect;
}

sub set_diff {
  ### in A not B
  ($a,$b) = @_;
  @diff = ();

  foreach (@{$b}) {
    $b{$_}=$_;
  }
  foreach (@{$a}) {
    push (@diff, $_) unless defined $b{$_};
  }
  return @diff;
}

