Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've also longed for a feature like this. I just cobbled this together, maybe this would be useful for you:
use strict; use IO::File; my $PODDIR = '/usr/share/perl/5.8.8/pod/'; my $CACHEDIR = "$ENV{HOME}/.podcache"; opendir(my $dir,$PODDIR) or die("failed to open pod directory"); unless(-d $CACHEDIR){ mkdir($CACHEDIR) or die("failed to build cache directory"); } while(my $f=readdir($dir)){ next unless $f =~ /\.pod$/; my $cache_file = "$CACHEDIR/$f.txt"; next if -f $cache_file; my $cache_fh = IO::File->new($cache_file,"w") or die("failed to buil +d cachefile $cache_file"); my @pod = `perldoc -t $PODDIR/$f`; for my $line (@pod){ print $cache_fh $line; } } my $pattern = $ARGV[0]; print `grep -r $pattern $CACHEDIR`

Set $PODDIR and $CACHEDIR to whatever values make sense on your system. And Here's how to use it. It accepts patterns grep accepts

username@servername$ perl podsearch qr/.*/ /home/username/.podcache/perl561delta.pod.txt: Dumping "qr//" o +bjects works correctly. /home/username/.podcache/perl5005delta.pod.txt: "lock" keyword", an +d "New "qr//" operator". /home/username/.podcache/perl5005delta.pod.txt: See "New "qr//" + operator". /home/username/.podcache/perl5005delta.pod.txt: New "qr//" operator /home/username/.podcache/perl5005delta.pod.txt: The "qr//" operator +, which is syntactically similar to the other /home/username/.podcache/perl56delta.pod.txt: Dumping "qr//" ob +jects works correctly. /home/username/.podcache/perl571delta.pod.txt: use MyFilter + qr/red/ => 'green'; /home/username/.podcache/perl571delta.pod.txt: +case qr/\w+/ { print "pattern" } /home/username/.podcache/perl58delta.pod.txt: use MyFilter +qr/red/ => 'green'; /home/username/.podcache/perl58delta.pod.txt: c +ase qr/\w+/ { print "pattern" } /home/username/.podcache/perlfaq6.pod.txt: separa +tor => qr/\s*,\s*/, /home/username/.podcache/perlfaq6.pod.txt: The qr// operator showed + up in perl 5.005. It compiles a regular /home/username/.podcache/perlfaq6.pod.txt: @patterns = map { qr +/\b$_\b/i } qw( foo bar baz ); /home/username/.podcache/perlfaq7.pod.txt: sufficiently recent +as to support the "qr//" construct, pass around /home/username/.podcache/perlfaq7.pod.txt: using "qr//": /home/username/.podcache/perlfaq7.pod.txt: $match = compare +("old McDonald", qr/d.*D/i); /home/username/.podcache/perlfaq7.pod.txt: Notice how "qr//" al +lows flags at the end. That pattern was compiled /home/username/.podcache/perlfaq7.pod.txt: at compile time, alt +hough it was executed later. The nifty "qr//" /home/username/.podcache/perlfaq7.pod.txt: here it is again if +you don't have "qr//": /home/username/.podcache/perlfunc.pod.txt: "m//", "pos", "quote +meta", "s///", "split", "study", "qr//" /home/username/.podcache/perlfunc.pod.txt: qr/STRING/ /home/username/.podcache/perlglossary.pod.txt: "q//", "qq//", " +qx//", "qw//", "qr//", "m//", "s///", "y///", and /home/username/.podcache/perlguts.pod.txt: r PERL_MAGIC_qr + vtbl_qr precompiled qr// regex /home/username/.podcache/perlop.pod.txt: change them, Perl +won't even notice. See also "qr/STRING/imosx". /home/username/.podcache/perlop.pod.txt: qr/STRING/imosx /home/username/.podcache/perlop.pod.txt: $rex = qr/my.S +TRING/is; /home/username/.podcache/perlop.pod.txt: $re = qr/$patt +ern/; /home/username/.podcache/perlop.pod.txt: my @compil +ed = map qr/$_/i, @$patterns; /home/username/.podcache/perlre.pod.txt: "s///", "qr//" and "??" in + "Regexp Quote-Like Operators" in perlop. /home/username/.podcache/perlre.pod.txt: used (see re), o +r the variables contain results of "qr//" /home/username/.podcache/perlre.pod.txt: operator (see "q +r/STRING/imosx" in perlop). /home/username/.podcache/perlre.pod.txt: 'Y|' => +qr/(?=\S)(?<!\S)|(?!\S)(?<=\S)/ ); /home/username/.podcache/perlreref.pod.txt: qr/pattern/imsox lets + you store a regex in a variable, /home/username/.podcache/perlretut.pod.txt: part of the "m//", "s// +/", "qr//" and "split" operators and so this /home/username/.podcache/perlretut.pod.txt: can be stored once and +used again and again. The regexp quote "qr//" /home/username/.podcache/perlretut.pod.txt: does exactly that: "qr/ +string/" compiles the "string" as a regexp and /home/username/.podcache/perlretut.pod.txt: $reg = qr/foo+bar?/ +; # reg contains a compiled regexp /home/username/.podcache/perlretut.pod.txt: @compiled = map qr/ +$_/, @regexp; /home/username/.podcache/perlretut.pod.txt: $pat = qr/(?{ $foo += 1 })/; # precompile code regexp /home/username/.podcache/perltoc.pod.txt: 'STRING', qq/STRI +NG/ , "STRING", qr/STRING/imosx , qx/STRING/ , /home/username/.podcache/perltoc.pod.txt: ARRAY,LIST , , q/ +STRING/, qq/STRING/, qr/STRING/, qx/STRING/, /home/username/.podcache/perltoc.pod.txt: New "qr//" operator /home/username/.podcache/perltoc.pod.txt: As a simple string, A +s a qr// compiled regular expression, e.g.:, As /home/username/.podcache/perltoc.pod.txt: As a simple string, A +s a qr// compiled regular expression, e.g.:, As

Shelling out with a tainted variable like $ARGV[0] is not particularly safe. So you'll probably want to play with sanitizing that variable.


In reply to Re: [perldoc] keyword search by thunders
in thread [perldoc] keyword search by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found