Sunday, December 5, 2010

Day 5: Check your Google PageRank with WWW::Google::PageRank

The Google PageRank is one factor in the placement of search results for Google. With WWW::Google::PageRank you can query the PageRank of any URL:
use WWW::Google::PageRank;
my $pr = WWW::Google::PageRank->new;
print scalar($pr->get('')), "\n";

Using the little advice from day 3 you can write it in one line:
perl -Maliased=WWW::Google::PageRank,PR -e 'print PR->new->get("")."\n"'

Ok, it does not quite fit into one line on this blog. :)
But I want to show you some options to '-M' here. Lets say you want use List::Util's 'max' function in your one liner. This is done by the '=' separator:
perl -MList::Util=max ...

All further imports have to be separated by ',':
perl -MList::Util=max,min ...

In the above example of aliased I use the two parameter form to give the alias an even shorter name ('PR'). The default would have been 'PageRank'.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.