Stupid perldoc-search trick

Perl's copious documentation is one of the things that keeps me using it. But this is not an unalloyed benefit; actually finding something, unless you have a pretty good idea where to start looking, can be like finding the proverbial needle in a haystack.

Fortunately, we have Joshua ben Jore's perldoc-search, which will find anything you can specify as a regular expression, and that Perl itself can find.

Unfortunately, this can sometimes be a bit too much. I generally have several Perl kits unpacked in my home directory (well, subdirectories of it). Since by default file-find does a File::Find::find on @INC, and since by default @INC contains my current directory, then if I issue a file-find in my home directory, the entire tree gets searched, and every unpacked kit can produce a hit.

It turns out there is a surely-unsupported but nonintrusive way to exclude the current directory from the search. Instead of running perldoc-search directly, run it as

perl -T -S perldoc-search

One of the things taint mode does is to exclude the current directory from @INC. Of course, taint mode does a lot more than that, all aimed at trying to ensure presumed-untrusted input can not modify output. So basically this trick only works because (as perlsec says) arguments to print are not checked for taintedness. If that ever changes, I will have to do something like patch in no lib '.';, and wonder whether that is portable. Until then, my .bashrc will contain a shell function that executes the above command with arguments "$@".

This trick was inspired by a Google search that turned up the article Current directory in @INC potentially harmful by Ansgar Burchardt.

PS - The no lib '.'; trick can also be done from the command line, using

perl -M-lib=. -S perldoc-search

Leave a comment

About Tom Wyant

user-pic Fine Perl code for over 0.005 centuries.