#!/usr/bin/perl use strict; use warnings; my ($by_module, $by_distro); ($by_module, $by_distro) = (1, 1) unless @ARGV; while (my $arg = shift(@ARGV)) { $by_module = 1 if lc($arg) =~ 'module'; $by_distro = 1 if lc($arg) =~ 'distro'; } my %total_downloads_by_module; my %total_downloads_by_distro; while (<>) { my ($url) = /\d{5}\s(.*)/; my @path = split /\// => $url; my $module_distro = pop @path; $total_downloads_by_distro{$module_distro}++ if $by_distro; if ($by_module) { my ($module) = ($module_distro =~ /(.*?)\-\d\..*?.tar\.gz/); $total_downloads_by_module{$module}++; } } format_report("Total Downloads by Module", %total_downloads_by_module) if $by_module; format_report("Total Downloads by Distro", %total_downloads_by_distro) if $by_distro; sub format_report { my ($header, %hash) = @_; print "+---------------------------------------\n"; print "| $header\n"; print "+------+--------------------------------\n"; print join "\n" => map { "| " . sprintf("%4d", $hash{$_}) . " | " . $_ } sort { $hash{$a} <=> $hash{$b} } keys %hash; print "\n+------+--------------------------------\n"; }