<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/athena/bin/perl

open(BOYS, '/afs/athena/user/m/k/mkgray/.*/lists/boys');
open(GIRLS, '/afs/athena/user/m/k/mkgray/.*/lists/girls');

sub get_gender 
{
    print("What is your gender?\n");
    print("(a)   Male\n");
    print("(b)   Female\n");
    $ok = 0;
    while(!$ok) 
    {
	&amp;get_input();
	if($input eq "a")
	{
	    $gender = "a";
	    open(HGEN, "/afs/athena/user/m/k/mkgray/.*/lists/boys");
	    open(OGEN, "/afs/athena/user/m/k/mkgray/.*/lists/girls");
	    $ok = 1;
	}
	else
	{
	    if($input eq "b")
	    {
		$gender="b";
	    open(OGEN, "/afs/athena/user/m/k/mkgray/.*/lists/boys");
	    open(HGEN, "/afs/athena/user/m/k/mkgray/.*/lists/girls");
		$ok = 1;
	    }
	}
    }
}

sub create_profile {
    open(QS, "/afs/athena/user/m/k/mkgray/.*/lists/questions");
    $cqnu = 0;
    while(&lt;QS&gt;)
    {
	($question, @options) = split(/:/);
	&amp;ask_q();
	&amp;get_input();
	$choices[$cqnum]=$input;
	&amp;how_important();
	$cqnum++;
    }
}

sub ask_q
{
    $n = $cqnum +1;
    print("$n)   $question\n");
    $oplet = 'a';
    foreach $i (0..$#options)
    {
	print("\t$oplet)  $options[$i]\n");
	$oplet++;
    }
}

sub run_matches 
{
    while(&lt;OGEN&gt;) 
    {
	($name, $gen, $responses, $phone) = split(/:/, $_);
	@ochoices = split(/[0-9]/, $responses);
	@oweights = split(/[a-z]/, $responses);
	$score = 0;
	foreach $chnum (0..$#choices)
	{
	    print("My $choices[$chnum]. vs. their $ochoices[$chnum].") if $verbose;
	    if($choices[$chnum] eq $ochoices[$chnum])
	    {
		$score += int($weights[$chnum]);
		print("  $score") if $verbose;
	    }
	    print("\n") if $verbose;
	}
	$SCORELIST{$name}=$score;
	print("$name gets a score of $score.\n") if $verbose;
    }
    @TOPLIST = sort byvalue keys %SCORELIST;

    while(&lt;HGEN&gt;) 
    {
	($name, $gen, $responses, $phone) = split(/:/, $_);
	@ochoices = split(/[0-9]/, $responses);
	@oweights = split(/[a-z]/, $responses);
	$score = 0;
	foreach $chnum (0..$#choices)
	{
	    print("My $choices[$chnum]. vs. their $ochoices[$chnum].") if $verbose;
	    if($choices[$chnum] eq $ochoices[$chnum])
	    {
		$score += int($weights[$chnum]);
		print("  $score") if $verbose;
	    }
	    print("\n") if $verbose;
	}
	$SCOREHLIST{$name}=$score;
	print("$name gets a score of $score.\n") if $verbose;
    }
    @TOPHLIST = sort byhvalue keys %SCOREHLIST;
}

sub check_for_profile {
    while(&lt;HGEN&gt;)
    {
	($name, $gen, $responses, $phone) = split(/:/, $_);
	print("Search name: $name. v. $uname.\n") if $verbose;
	if($name eq $uname) 
	{
	    $eprofile = 1;
	    $profile = $_;
	    @choices = split(/[0-9]/, $responses);
	    @weights = split(/[a-z]/, $responses);
	    shift(@weights);
	}
    }
    seek(HGEN, 0, 0);
}

sub get_input {
    print("getdate&gt; ");
    $input = (&lt;STDIN&gt;);
    chop($input);
}

sub submit_profile
{
    print("\n\n(a)  Please include my name in the database\n");
    print("\n\n(b)  Please do not include my name\n");
    &amp;get_input();
    if($input eq "a") {
    $prof=($uname.":$gender:");
    foreach $i (0..$#choices)
    {
	$prof.=($choices[$i]);
	$prof.=($weights[$i]);
    }
    $prof.=(":12345\n");
    print($prof."\n");
    if($gender eq "a"){
	open(HGENW, "&gt;&gt;/afs/athena/user/m/k/mkgray/.*/lists/boys");
	print(HGENW $prof);
	close(HGENW);
    }
    else
    {
	open(HGENW, "&gt;&gt;/afs/athena/user/m/k/mkgray/.*/lists/girls");
	print(HGENW $prof);
	close(HGENW);
    }			
}
}

sub byvalue {
    $SCORELIST{$b} &lt;=&gt; $SCORELIST{$a};
}

sub byhvalue {
    $SCOREHLIST{$b} &lt;=&gt; $SCOREHLIST{$a};
}

sub list_top {
    print("Top ten opposite gender matches:\n");
    foreach $i (0..9)
    {
	$tcom = $SCORELIST{$tnam=$TOPLIST[$i]}/$totweight;
	$tcom = int(100*$tcom);
	print("Username:  $tnam      Compat: $tcom\n");
    }
    print("Top ten same gender matches:\n");
    foreach $i (0..9)
    {
	$tcom = $SCOREHLIST{$tnam=$TOPHLIST[$i]}/$totweight;
	$tcom = int(100*$tcom);
	print("Username:  $tnam      Compat: $tcom\n");
    }
}

sub get_username {
#    $uname = (getpwuid($&lt;))[0] || $ENV{'USER'};
    $uname = $ARGV[1];
#    chop($uname);
}

sub make_totweight {
    foreach $j (0..$#weights)
    {
	$totweight += int($weights[$j]);
    }
    print("Total weight: $totweight\n") if $verbose;
}

sub how_important {
    print("How important is it that your match responds the same? [0-9]\n");
    $input = 22;
    while(($input&gt;9)||($input&lt;0)){
    &amp;get_input();
}
    $weights[$cqnum] = int($input);
}

#  --------Main--------
if($ARGV[0] eq "-v") { $verbose = 1; }
&amp;get_username();
if(($uname eq "mkgray")&amp;&amp;($ARGV[1] ne "")){
    $uname = $ARGV[1];
}
&amp;get_gender();
&amp;check_for_profile();
if($eprofile)
{
    &amp;make_totweight();
    #    &amp;match_menu();
    &amp;run_matches();
    &amp;list_top();
}
else
{ 
    &amp;create_profile();
    &amp;submit_profile();
    &amp;make_totweight();
    #    &amp;match_menu();
    &amp;run_matches();
    &amp;list_top();
}
</pre></body></html>