#!/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
In reply to perldoc.cgi by ccn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |