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


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.