in reply to [Solved] Wrapping code in a sub causes an error I don't understand.

Note the error happens regardless of the presence of the sub main; that's not what's causing it, instead it is Pod::Usage trying to read the POD. From its documentation (emphasis mine):

-input handle
A reference to a filehandle, or the pathname of a file from which the invoking script's pod documentation should be read. It defaults to the file indicated by $0 ($PROGRAM_NAME for users of English.pm).

And when you run Perl with the -e switch, the $0 variable will be "-e", which is where the error message is coming from; it's trying to open a file with that name. The documentation further goes on to state:

If you are calling pod2usage() from a module and want to display that module's POD, you can use this:
use Pod::Find qw(pod_where); pod2usage( -input => pod_where({-inc => 1}, __PACKAGE__) );

Which, when applied to your example code, works for me.

Replies are listed 'Best First'.
Re^2: Wrapping code in a sub causes an error I don't understand.
by davies (Monsignor) on Aug 31, 2023 at 09:44 UTC

    And it works for me. Thank you. I was, as you have spotted, floundering and it would have taken me a very long time to find your answer on my own.

    Regards,

    John Davies