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.
In reply to Re: Wrapping code in a sub causes an error I don't understand.
by haukex
in thread [Solved] Wrapping code in a sub causes an error I don't understand.
by davies
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |