davies has asked for the wisdom of the Perl Monks concerning the following question:
The file below, with two lines commented out, works as I expect.
use strict; use warnings; package Sscce; use Getopt::Long; use Pod::Usage; my ($opt_help, $opt_man, ); # sub main { GetOptions( 'help' => \$opt_help, 'man' => \$opt_man, ) or pod2usage(-verbose => 1) && exit; pod2usage(-verbose => 1) && exit if defined $opt_help; pod2usage(-verbose => 2) && exit if defined $opt_man; # } 1; =pod =head1 NAME =head1 ARGUMENTS =head1 OPTIONS --help Brief manual --man Full manual
Running the file gives the output below:
X:\Data\Perl\NoFile>perl Sscce.pm -h Arguments: Options: --help Brief manual --man Full manual X:\Data\Perl\NoFile>perl Sscce.pm -m NAME ARGUMENTS OPTIONS --help Brief manual --man Full manual
But if the two comment lines are uncommented and the calling command changed, I get an error:
X:\Data\Perl\NoFile>Perl -I. -MSscce -e"Sscce::main @ARGV" -- -h Can't open -e: No such file or directory at Sscce.pm line 17.
I fear that I have no idea how to approach this. Adding diagnostics gives more data:
X:\Data\Perl\NoFile>Perl -I. -MSscce -e"Sscce::main @ARGV" -- -h Can't open -e: No such file or directory at Sscce.pm line 18 (#1) (S inplace) The implicit opening of a file through use of the <> filehandle, either implicitly under the -n or -p command-line switches, or explicitly, failed for the indicated reason. Usually this is because you don't have read permission for a file which you named on the command line. (F) You tried to call perl with the -e switch, but /dev/null (or your operating system's equivalent) could not be opened. Uncaught exception from user code: Can't open -e: No such file or directory at Sscce.pm line 18. Pod::Simple::parse_file(Pod::Usage=HASH(0x262f6a8), "-e") call +ed at C:/Strawberry/perl/lib/Pod/Text.pm line 737 Pod::Text::parse_file(Pod::Usage=HASH(0x262f6a8), "-e") called + at C:/Strawberry/perl/site/lib/Pod/Simple.pm line 535 Pod::Simple::parse_from_file(Pod::Usage=HASH(0x262f6a8), "-e", + GLOB(0x2623f40)) called at C:/Strawberry/perl/lib/Pod/Text.pm line 7 +06 Pod::Text::parse_from_file(Pod::Usage=HASH(0x262f6a8), "-e", G +LOB(0x2623f40)) called at C:/Strawberry/perl/lib/Pod/Usage.pm line 17 +9 Pod::Usage::pod2usage("-verbose", 1) called at Sscce.pm line 1 +8 Sscce::main(GLOB(0x2623f40)) called at -e line 1
Unfortunately, going through the code points listed has left me none the wiser. I'd be grateful for any help.
Regards,
John Davies
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Wrapping code in a sub causes an error I don't understand.
by haukex (Archbishop) on Aug 30, 2023 at 21:44 UTC | |
by davies (Monsignor) on Aug 31, 2023 at 09:44 UTC | |
Re: Wrapping code in a sub causes an error I don't understand.
by hv (Prior) on Aug 30, 2023 at 23:23 UTC | |
Re: Wrapping code in a sub causes an error I don't understand.
by hippo (Archbishop) on Aug 30, 2023 at 21:51 UTC | |
by davies (Monsignor) on Aug 31, 2023 at 09:48 UTC | |
by hippo (Archbishop) on Aug 31, 2023 at 11:02 UTC |