afoken has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I have a module with a rather large hash containing default values, and I want to document the key-value pairs right where I define them.

Perfectly working test case, missing POD:

#!/usr/bin/perl -w use strict; my %data=( a => 1, b => 2, ); print join(' ',%data);

The same test case, with POD near the key-value pairs:

#!/usr/bin/perl -w use strict; my %data=( =head1 The "a" key one =cut a => 1, =head1 The "b" key two =cut b => 2, ); print join(' ',%data);

This does not even compile, perl is completely confused about the POD and seems to read it as code:

Bareword found where operator expected at pod-in-structure.pl line 7, +near ""a" key" (Missing operator before key?) Bareword found where operator expected at pod-in-structure.pl line 15, + near ""b key" (Missing operator before key?) syntax error at pod-in-structure.pl line 7, near "( =" Execution of pod-in-structure.pl aborted due to compilation errors.

This happens with perl 5.8.8 on Linux and Strawberry 5.10.0. All blank lines are completely empty, there are no spaces or tabs in those lines. All POD starts in the first column.

As far as I understood the documentation, I should be able to inline POD everywhere outside here-documents. But my two perl binaries seem to have a different oppinion.

So, is there a way to embed POD into a hash definition, is perl broken, or did I miss a piece of documentation?

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re: I'm confused because perl is confused with POD
by moritz (Cardinal) on Jun 30, 2009 at 21:10 UTC
    As far as I understood the documentation, I should be able to inline POD everywhere outside here-documents.

    What part of the documentation suggests that? It would need fixing, it seems.

    To the best of my knowledge POD is only allowed between statements, not everywhere.

    Update: perlsyn says

    Perl has a mechanism for intermixing documentation with source code. While it’s expecting the beginning of a new statement, if the compiler encounters a line that begins with an equal sign and a word, like this

    which pretty much confirms my knowledge

      Thanks! That was the documentation I searched for.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: I'm confused because perl is confused with POD
by Utilitarian (Vicar) on Jul 01, 2009 at 06:47 UTC
    POD isn't really for inline comments, though it can make the intention of the source clearer if explanations are close to the code that provides the functionality described.

    POD is used to provide a "man page" for the user, for inline explanations to someone reading the code the "#comment" is more appropriate.

      You are completely right, but in this case, the documentation of the hash pairs WAS the biggest part of the man page. I've changed the code a little so that I can mix POD and hash pairs properly.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)