http://www.perlmonks.org?node_id=905522


in reply to Re^3: Embedding pod in C
in thread Embedding pod in C

A followup to my own followup (but not as a reply, which could drive the depth of the replies below the default level of visibility).

The preprocessor could take, as arguments, two patterns to identify the start and the end of the pod block. This would make it more general than something dependent on C conventions.

Update: and maybe another pattern to determine what should be deleted from the start of each line in the pod block, so we don't have to rely on white space.

Update #2: First approximation (missing way to set patterns):

#!/usr/bin/perl -w use strict; my $start = qr{^.*#\s*ifdef\s+pod}; my $stop = qr{^.*#\s*endif\s*/\*\s*pod\s*\*/}; my $trim = qr{^\s*}; my $verb = qr{^\s*=v\s}; my $show = 0; while ( my $line = <DATA> ) { if ( $line =~ $start ) { $show = 1; next; } if ( $line =~ $stop ) { $show = 0; next; } if ($show) { chomp($line); $line =~ s/$trim//; $line =~ s/$verb//; print $line, "\n"; } } __DATA__ This could be anything #ifdef pod =head2 title blah, blah,blah =v indent 1 #endif /* pod */ This could be anything, too