#!/usr/local/bin/perl
#
#  hosts-domain - counts the number of hosts per domain
#          	  The host names should be absolute (see expand) and in the
#		  first column of input (see hosts)
#
#  Copyright (C) 1992, 1993 PUUG - Grupo Portugues de Utilizadores
#                                  do Sistema UNIX
#                1992, 1993 FCCN - Fundacao para o Desenvolvimento dos Meios 
#                                  Nacionais de Calculo Cientifico 
#
#  Authors: Jorge Frazao de Oliveira <frazao@puug.pt>
#           Artur Romao <artur@dns.pt>
#
#  This file is part of the DDT package, Version 2.0.
#
#  Permission to use, copy, modify, and distribute this software and its 
#  documentation for any purpose and without any fee is hereby granted,
#  provided that the above copyright notice appear in all copies.  Neither
#  PUUG nor FCCN make any representations about the suitability of this
#  software for any purpose.  It is provided "as is" without express or 
#  implied warranty.


$[ = 1;			# set array base to 1

while (<STDIN>) {
    	($Name) = split(/\s+/, $_);

    	@label = split(/\./, $Name);
	$n = $#label;

    	$domain = $label[$n];	# topmost domain

    	foreach $i ($[ .. $n - 1) {
		$hosts{$domain}++;

		# build the domain name backwards
		$domain = join(".", $label[$n - $i], $domain);
    	}
}

foreach $dom (keys %hosts) {
    	printf "%5d %s\n", $hosts{$dom}, $dom;
}

