#!/usr/bin/perl -w use strict; use URI::Escape; chdir '/tmp'; # if possible my $name = (split '/', $ENV{SCRIPT_NAME} || $0)[-1]; print "Content-type: text/html\n\n"; uri_unescape($ENV{QUERY_STRING} || 'perldoc') =~ /^([\w\s:-]*)$/ or do { print "bad query string: $ENV{QUERY_STRING}"; exit; }; open DOC, "perldoc -u $1|pod2html --header --title='$1'|" or do { print "can't run perldoc: $!"; exit; }; while (<DOC>) { s{ href="/([^."]+)\.html } { local $_ = $1; s|/|::|g; qq(href="$name?$_) }gexi; print; }
Usage:
UPDATE: thanks to tachyon for suggestions
I've chosen deafult argument 'perldoc' instead of error reporting on empty query,
2>/dev/null added,
relative_path used instead of hardcoded 'perldoc.cgi'
fork eliminated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perldoc.cgi
by tachyon (Chancellor) on Oct 10, 2004 at 11:45 UTC | |
|
Re: perldoc.cgi
by tachyon (Chancellor) on Oct 10, 2004 at 22:35 UTC | |
by ccn (Vicar) on Oct 11, 2004 at 09:02 UTC | |
|
Re: perldoc.cgi
by Anonymous Monk on Oct 10, 2004 at 12:05 UTC | |
|
Re: perldoc.cgi
by elwarren (Priest) on Oct 11, 2004 at 15:53 UTC |