<%INIT> use LWP::Simple; my $maxcount = 5; my $referer = $r->header_in( 'Referer' ); my ($www,$tld) = $referer =~ /(www\.)?perlmonks\.(\w+)/i; $tld ||= 'org'; my ($count,$title,$author,$node,$html); while ($title eq $author) { last if $count++ >= $maxcount; $html = get("http://perlmonks.com/index.pl?op=randomnode"); ($node) = $html =~ /\blastnode_id=(\d+)/; ($title) = $html =~ /([^>]+)<\/title>/i; ($author) = $html =~ /\bby\s*<A HREF[^>]+>([^<]+)<\/A>/i; } my $redirurl = "http://${www}perlmonks.$tld/index.pl?node_id=$node"; $m->comp('/comps/redirect.cmp', url=>$redirurl); </%INIT>