Changeset 7494
- Timestamp:
- 08/23/09 23:27:21 (2 years ago)
- File:
-
- 1 edited
-
trunk/tools/parse_perlopref.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/parse_perlopref.pl
r7328 r7494 2 2 use warnings; 3 3 4 # 5 # Parse an online perlopref.pod and returns a hash of topics and help 6 # 7 sub parse_perlopref { 8 my $url = shift; 9 10 print "Loading $url\n"; 11 require LWP::UserAgent; 12 require HTTP::Request; 13 my $ua = LWP::UserAgent->new; 14 my $req = HTTP::Request->new(GET => $url); 15 my $res = $ua->request($req); 16 if(not $res->is_success) { 17 die $res->status_line, "\n"; 18 } 19 20 # Open perlopref 21 my $fh; 22 my $content = $res->content; 23 open $fh, "<", \$content; 24 25 26 my %index = (); 27 28 # Add PRECEDENCE to index 29 until (<$fh> =~ /=head1 PRECEDENCE/) { } 30 31 my $line; 32 while($line = <$fh>) { 33 last if($line =~ /=head1 OPERATORS/); 34 $index{PRECEDENCE} .= $line; 35 } 36 37 # Add OPERATORS to index 38 my $op; 39 while($line = <$fh>) { 40 if($line =~ /=head2\s+(.+)$/) { 41 $op = $1; 42 } elsif($op){ 43 $index{$op} .= $line; 44 } 45 } 46 47 # and we're done 48 close $fh; 49 50 return %index; 4 my $url = 'http://github.com/cowens/perlopref/raw/master/perlopref.pod'; 5 print "Loading $url\n"; 6 require LWP::UserAgent; 7 require HTTP::Request; 8 my $ua = LWP::UserAgent->new; 9 my $req = HTTP::Request->new(GET => $url); 10 my $res = $ua->request($req); 11 if(not $res->is_success) { 12 die $res->status_line, "\n"; 51 13 } 52 14 53 my %op_ref = parse_perlopref 'http://github.com/cowens/perlopref/raw/456675100b4e4b7fb048e7fa2b525bcf7145070c/perlopref.pod'; 54 print "Indexed " . (scalar keys %op_ref) . " topic\n"; 15 print $res->content; 55 16 56 17 __END__ … … 58 19 =head1 NAME 59 20 60 parse_perlopref.pl - A script to parse perlopref 21 update_perlopref.pl - A script to download the latest copy of perlopref.pod from github 61 22 62 23 =head1 DESCRIPTION 63 24 64 This is a simple script to load perlopref.pod from github and generate an index65 which we can re-use in Padre Help Search. 25 This is a simple script to load perlopref.pod from github and write it in its 26 proper Padre folder 66 27 67 28 =head1 AUTHOR
Note: See TracChangeset
for help on using the changeset viewer.
