Hi Francois

Do what works. If you're only parsing your own POD, then what you're doing now should be OK.

I would like (one day!) to write a BNF for POD and use Marpa:

http://savage.net.au/Marpa.html

About 10 of the Perl packages there are mine.

If you intend to create a module fit for CPAN, then of course it's a bigger decision as to the internal structure of your code.

On 29/03/17 17:09, RAPPAZ Francois via pod-people wrote:
Hi Ron,

Thanks for the suggestion.

At the end, reading the pod file and capturing the key from head1 is easy 
(below).  I could use a Pod::Simple::SimpleTree  , but I would still to have 
the output as raw pod. Probably using a parser to select pars of pod is not a 
good idea ?

François

my $fname = shift;
 my $mod;
    open $mod, "<$fname" or die "Can't open $fname $! \n";
    my %data;
    my $data_ar;
    my $key;
    my $ispod;
    for my $line (<$mod>) {
        chomp $line;
        if ( $line =~ /^=cut/ ) { $ispod = 0; }
        if ( $line =~ /^=head1\s*(.+)$/i ) {
            $ispod = 1;
            if ($key) {    #$key read from the previous =head1
                $data{$key} = $data_ar;    #store the array of lines as an 
array ref
                $data_ar = undef;          # and prepare a new array
            }
            $key = $1;                     #now fetch the new value for $key
        }
        push @{$data_ar}, $line  if ($ispod) ;    #store the line in the array 
if we are in a pod section

    }
    close $mod;
    $data{$key} = $data_ar;    #fetch the lines from the last =head1 read
=for comment
    for $key ( keys %data ) {
        print "*$key*\n";
        print join( "\n", @{ $data{$key} } ), "\n";

    }
=cut
    return %data;

-----Original Message-----
From: Ron Savage [mailto:r...@savage.net.au]
Sent: 28 March 2017 23:36
To: pod-people@perl.org
Subject: Re: raw_data with Pod::Simple::PullParser

Hi François

Can't help specifically but I do suggest you use a tree rather than a hash. It 
just makes much more sense to me to store the pod that way.

--
Ron Savage - savage.net.au


--
Ron Savage - savage.net.au

Reply via email to