develooper Front page | perl.perl5.porters | Postings from June 2008

[PATCH] "perldoc -q ..." search index entries (X<>) for pattern

From:
renee.baecker
Date:
June 6, 2008 06:39
Subject:
[PATCH] "perldoc -q ..." search index entries (X<>) for pattern
Message ID:
20080606133942.EF78F1201A6@rserv16.sitepush.net
In the perlfaqs there are index entries (X<>) for many FAQs, but these
entries aren't searched for the pattern as they are not in the
headline.

This patch searches the index entries if they are in the line after the
headline.

In the past you have to add new words to the headline if you wanted them
to be found via "perldoc -q". Now you just have to add a new index
entry...

Example:

Entry in perlfaq5.pod:

=head2 How can I use Perl's C<-i> option from within a program?
X<-i> X<in-place>

...

Without the patch:

C:\usr\lib\Pod>perldoc -q in-place
No documentation for perl FAQ keyword `in-place' found

With patch applied:

C:\usr\lib\Pod>perldoc -q in-place
Found in C:\usr\lib\pods\perlfaq5.pod
  How can I use Perl's "-i" option from within a program?

    "-i" sets the value of Perl's $^I variable, which in turn affects
the
    behavior of "<>"; see perlrun for more details. By modifying the
    appropriate variables directly, you can get the same behavior within
a
    larger program. For example:

            # ...
            {
            local($^I, @ARGV) = ('.orig', glob("*.c"));
            while (<>) {
                    if ($. == 1) {
                            print "This line should appear at the top of
each fi
le\n";
                    }
                    s/\b(p)earl\b/${1}erl/i;        # Correct typos,
preserving
case
                    print;
                    close ARGV if eof;              # Reset $.
                    }
            }
            # $^I and @ARGV return to their old values here

    This block modifies all the ".c" files in the current directory,
leaving
    a backup of the original data from each file in a new ".c.orig"
file.


C:\usr\lib\Pod>

Cheers,
Renee


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About