Wednesday, November 5, 2008

Finding Best Linux Distribution

We can find ranking of Linux distributions (distros) at site distrowatch.com. This ranking is based on Page Hits Per Day.In order to find best Linux distro, I have written a Perl script:

#!/usr/bin/perl -w
#===============================================================================
#
# FILE: best_distro.pl
#
# USAGE: ./best_distro.pl
#
# DESCRIPTION: Finds best distro from distrowatch.com
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Mitesh Singh Jat (mitesh)
# VERSION: 1.0
# CREATED: Tuesday 04 November 2008 04:05:19 IST
# REVISION: ---
#===============================================================================

use strict;
use warnings;

my $ndistro = 1;

if (@ARGV >= 1)
{
$ndistro = $ARGV[0];
if ($ndistro > 100)
{
$ndistro = 100;
}
}

my $lynx = `which lynx`;
chomp($lynx);
if ($lynx eq "")
{
print STDERR "$0: please install lynx\n";
print STDERR "sudo apt-get install lynx\n";
exit(-1);
}

open(LYNX, "lynx -source http://distrowatch.com/ |") or die("$0: cannot open lynx: $!\n");

my $i = 1;

while ($i <= $ndistro)
{
my $line;
my $distro;
my $rank = "";
while ($line = <LYNX>)
{
chomp($line);
$line =~ s/<th class=([^>]*)>(.*?)<\/th>/$2/i;
$line =~ s/(\s+)//g;
if ($line eq "$i")
{
$rank = $line;

unless ($line = <LYNX>) {last;}
chomp($line);
$line =~ s/<td class=([^>]*)><a href=([^>]*)>(.*?)<\/a><\/td>/$3/i;
$line =~ s/(\s+)//g;
$distro = $line;

print "$rank\t$distro\n";
last;
}
}
++$i;
}

close(LYNX);

Sample runs of above program:
$ ./best_distro.pl
1 Ubuntu
$ ./best_distro.pl 5
1 Ubuntu
2 openSUSE
3 Mint
4 Fedora
5 Debian

No comments: