http://www.perlmonks.org?node_id=83785

I know. Forgot my towel on 25th. This is an attempt to apologize :). A medium snippet (or a little program, if you prefear) to dig through the Galactic Guide.

Update: Another good Guide: http://www.vogon.com/guide/

Update: Following jepri's advice, topic can come from command-line.

#!/usr/bin/perl use strict; use LWP::Simple; use HTML::Parser; my $in_article_body = 0; my $colin = HTML::Parser->new( start_h => [sub { my $self = shift; my ($tagname, $attr) = @_; if ($tagname eq "div" && $attr->{class} eq 'article') { $in_article_body = 1;; } }, "self, tagname, attr"], end_h => [sub { my $self = shift; my ($tagname) = @_; if ($tagname eq "div" && $in_article_body) { $in_article_body = 0; } }, "self, tagname"], text_h => [sub { my $self = shift; my ($origtext) = @_; print $origtext if $in_article_body; }, "self, text"]); my $topic = $ARGV[0] || 'perl'; my $url = "http://www.galactic-guide.com/cgi-bin/articlesearch.cgi?sea +rchval=$topic"; my $string = get( $url ); # It works like Google's "I'm feeling lucky"-mode if ($string =~ /1\. <a href="([^"]*)/ ) { my $new_url = "http://www.galactic-guide.com$1"; my $text = get( $new_url ); $colin->parse( $text ); } else { print "There aren't pages about $topic\n"; }

Replies are listed 'Best First'.
Re: No panic! (Hitch hikers' facility)
by jepri (Parson) on May 29, 2001 at 10:00 UTC
    That's a nice program. I was confused for a while because no matter what I typed in at the command line, it printed out the geek code. For a moment I thought that was the joke.

    A line like $topic = $ARGV[0] ? shift @ARGV : 'perl'; would give it nice command line functionality. Then I could include it in shell scripts and the like :)

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.