Created
April 11, 2011 18:42
-
-
Save chetan/914034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
=cut | |
browser_breakdown.pl | |
(c) 2011, Chetan Sarva <chetan@evidon.com> | |
Takes a list of User Agents via STDIN and prints out browser and platform summaries. | |
Example summary: | |
Total User Agents: 11279 | |
Browser breakdown: | |
unknown 0% (55) | |
AOL Browser 1% (149) | |
Chrome 16% (1769) | |
Firefox 8% (906) | |
MSIE 74% (8347) | |
Mobile Safari 0% (2) | |
RealPlayer 0% (46) | |
Safari 0% (5) | |
Platform breakdown: | |
unknown 0% (55) | |
Linux 0% (31) | |
Mac OS X 3% (317) | |
Unix 0% (2) | |
Win2k 0% (3) | |
Win2k3 1% (80) | |
Win7 32% (3556) | |
Win98 0% (1) | |
WinVista 16% (1848) | |
WinXP 48% (5386) | |
=cut | |
use HTTP::BrowserDetect; | |
my $browsers = {}; | |
my $platforms = {}; | |
my $c = 0; | |
while (<>) { | |
chomp; | |
my $b = HTTP::BrowserDetect->new($_); | |
my $ua = $b->browser_string(); | |
my $p = $b->os_string(); | |
if ($browsers->{$ua}) { | |
$browsers->{$ua}++; | |
} else { | |
$browsers->{$ua} = 1; | |
} | |
if ($platforms->{$p}) { | |
$platforms->{$p}++; | |
} else { | |
$platforms->{$p} = 1; | |
} | |
$c++; | |
} | |
print "\n"; | |
print "Total User Agents: $c\n\n"; | |
print "Browser breakdown: \n\n"; | |
my $l = 6; | |
for (sort keys %$browsers) { | |
$l = length $_ if length $_ > $l; | |
} | |
for my $k (sort keys %$browsers) { | |
my $v = $browsers->{$k}; | |
my $p = sprintf("%.00f", $v / $c * 100); | |
print " " . ($k || "unknown") . (" " x ($l - length ($k || "unknown"))) . "\t\t$p\%\t($v)\n" | |
} | |
print "\n\nPlatform breakdown: \n\n"; | |
$l = 6; | |
for (keys %$platforms) { | |
$l = length $_ if length $_ > $l; | |
} | |
for my $k (sort keys %$platforms) { | |
my $v = $platforms->{$k}; | |
my $p = sprintf("%.00f", $v / $c * 100); | |
print " " . ($k || "unknown") . (" " x ($l - length ($k || "unknown"))) . "\t\t$p\%\t($v)\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment