[doc://perlfaq5#How-can-I-use-Perl's--i-option-from-within-a-program?] How can I use Perl's i option from within a program?
die fudge(q{http://perldoc.perl.org/perlfaq5.html#How-can-I-use-Perl%2
+7s--i-option-from-within-a-program%3f});
sub fudge {
local $_ = shift ;
return $_ if not m{\Qhttp://perldoc.perl.org/\E|\Qdoc://\E}si; # d
+on't deal
return $_ if m{\Qhttp://perldoc.perl.org/5.\E}si; # don't deal
s/^\[//;
s/\]$//;
my $right = "";
s{\|(.*)}{} and $right.= $1;
s{^\Qhref://\E}{}si;
s{^\Qhttp://perldoc.perl.org/\E}{}si;
s{^\Qdoc://\E}{}si;
s{\Q.html\E}{}si;
my( $left, $anchor ) = split '#', $_, 2;
$left =~ s{/}{::}g;
if( m{%[a-zA-Z0-9]{2}}si ){
$_ = unescape( $anchor ) ;
s/ /-/;
$anchor = $_;
}
if( $anchor ){
$anchor =~ s{\[}{%5b}g;
$anchor =~ s{\]}{%5d}g;
$left .= '#' . $anchor ;
}
if( length $right ){
$right =~ s{\[}{[}g;
$right =~ s{\]}{]}g;
return "[doc://$left|$right]" ;
}
return "[doc://$left]";
}
sub Main {
for my $file ( ( glob 'perlfaq*.html' ), (glob 'perlpod*html' ), (
+'perlintro.html', 'perlop.html') ){
( my $name = $file ) =~ s/\.html//;
#~ dd [ $file => $name ];
my $tree = HTML::TreeBuilder->new;
$tree->parse_file( $file );
$tree->look_down(
_tag => "a",
name => qr/./,
sub {
my $question = $_[0]->attr('name');
return if $question =~ m{
^\s*
(?:
AUTHOR.AND.COPYRIGHT
| NAME
| DESCRIPTION
| CREDITS
| THE.QUESTIONS
| TABLE.OF.CONTENTS
)
\s*$}xs;
print fudge("[doc://$name#$question]"), "\n";
0;
},
);
}
}