[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
[PATCH] "perldoc -q ..." search index entries (X<>) for pattern
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
--- Perldoc.pm.old 2008-06-06 15:26:00.795670900 +0200
+++ Perldoc.pm 2008-06-06 15:25:29.199761100 +0200
@@ -942,6 +942,10 @@
die "invalid file spec: $!" if $file =~ /[<>|]/;
open(INFAQ, "<", $file) # XXX 5.6ism
or die "Can't read-open $file: $!\nAborting";
+
+ my $tmp_text = "";
+ my $header = 0;
+
while (<INFAQ>) {
if ( m/^=head2\s+.*(?:$search_key)/i ) {
$found = 1;
@@ -949,7 +953,19 @@
}
elsif (/^=head[12]/) {
$found = 0;
+ $tmp_text = $_;
+ $header = 1;
}
+
+ if ( $header and !/^=head[12]/ ){
+ if( m!X<[^>]*(?:$search_key).*?>! ){
+ $found = 1;
+ push @$pod, "=head1 Found in $file\n\n" unless $found_in{$file}++;
+ push @$pod, $tmp_text;
+ }
+ $header = 0;
+ }
+
next unless $found;
push @$pod, $_;
}
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]