in reply to Parse POD of a method from perl module
G'day perlUser9,
Welcome to the monastery.
This seems to do what you want. Using your example code, this outputs just "My POD for Subroutine2\n". I added some extra dummy POD for test purposes.
#!/usr/bin/env perl use strict; use warnings; my $wanted_sub = 'Subroutine2'; my $pod_string; { local $/ = "\n=head1 "; while (<DATA>) { if (/\A $wanted_sub $/mx) { ($pod_string = $_) =~ s/\A .+? ^ ( .+? ) =cut .* \z/$1/msx +; last; } } } print $pod_string; __DATA__ package MyModule; =head1 Subroutine1 My POD for Subroutine1 =cut sub Subroutine1 { ... ... } =head1 Subroutine2 My POD for Subroutine2 =head2 Dummy Heading 2 =over 4 =item whatever qwerty =item blah asdfgh =back Some text =cut sub Subroutine2 { ... ... } 1;
Output:
My POD for Subroutine2 =head2 Dummy Heading 2 =over 4 =item whatever qwerty =item blah asdfgh =back Some text
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parse POD of a method from perl module
by Anonymous Monk on May 15, 2014 at 05:13 UTC |