#!/afs/athena/contrib/perl/p

# Require some usefull stuff
require 'getopts.pl';

# Build some handy associative arrays
#
# meta/internet/mkt/$key has a value of company name
%adindex = ('austin', 'The Austin Code Works',
	    'nearnet', 'Bolt Beranek and Newman Inc.',
	    'clyatt', 'Clyatt Immigration Law Services',
	    'cocorp', 'The Company Corporation',
	    'cpsr', 'Computer Professionals for Social Responsibility',
	    'cucumber', 'Cucumber Information Services',
	    'decus', 'DECUS U.S. Chapter',
	    'delphi', 'Delphi',
	    'digital', 'Digital Equipment Corporation',
	    'earthShare', 'EarthShare',
	    'ecosoft', 'Eco Software, Inc.',
	    'fose', 'FOSE',
	    'first.step', 'Hand in Hand',
	    'heller', 'Heller, Ehrman, White, &amp; McAuliffe',
	    'inner.circle', 'Inner Circle',
	    'tig', 'The Internet Group',
	    'lens', 'Lens Express, Inc.',
	    'lp', 'Lonely Planet Publications',
	    'macsyma', 'Macsyma, Inc.',
	    'mathworks', 'MathWorks, Inc.',
	    'mcet', 'MCET',
	    'merrimack', 'Merrimack College',
	    'microplex', 'Microplex',
	    'mfsl', 'Mobile Fidelity Sound Lab',
	    'morningstar', 'Morning Star Technologies',
	    'sobek', 'Mountain Travel*Sobek ',
	    'nrh', 'Niehaus Ryan Haller Public Relations, Inc.',
	    'nordic', 'NordicTrack',
	    'omg', 'OMG',
	    'ora', 'O\'Reilly &amp; Associates, Inc.',
	    'seniorNet', 'SeniorNet',
	    'tt', 'Travelers\' Tales Books',
	    'usenix', 'USENIX Organization',
	    'white.pine', 'White Pine Software',
	    'windata', 'Windata, Inc.',
	    'xpo', 'XPO',
	    'zcode', 'Z-Code Corporation',
	    );

# Main program
#&usage unless &Getopts('');

# Main loop
while(<>){
    $total++;
    next unless m,meta/internet/mkt/,;
    split;
    $host = $_[0];
    (@pparts) = split(/\//, $_[7]);
    $markets{$pparts[4]}++;
    $evalme = "\$$pparts[4]\{\'$host\'\}++", "\n";
    eval($evalme);
    $count++;
    if($count/100 == int($count/10)){
	print("Market hits: $count (out of $total hits)\n");
    }
}

for $market (keys %markets) {
    print("\n\n--------------------\n$adindex{$market} [$market]\n-------------------\n");
    $evalme = "\%mymarket = \%$market";
    eval($evalme);
    $evalme = "\@hosts = keys \%$market";
    eval($evalme);
    @shosts = sort {$mymarket{$b} <=> $mymarket{$a}} @hosts;

    for $h (@shosts){
	print("$h: $mymarket{$h}\n");
    }
}
