John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Any idea what this means? I want Getoptions to not itself generate warning/error output even if I call it with incorrect arguments. This looks like internal stuff.

GetOptions ( 'help|?|h' => \&show_options, 'verbose!' => \$verbose, 'v' => \$verbose, 'L=s' => \@linkfiles, 'RC=s' => $RCfile, 'fixtarget!' => $fixtarget, 'midlopts=s' => $midlopts ) or die;
produces 3 warnings on line 303 and three on line 322.
Use of uninitialized value in pattern match (m//) at ../LIB\Getopt\Lon +g.pm (autosplit into ..\lib\auto\Getopt\Long\GetOp tions.al) line 303.

Replies are listed 'Best First'.
Re: Error inside Getopt::Long
by runrig (Abbot) on Oct 12, 2001 at 23:16 UTC
    Shouldn't $RCfile, $fixtarget, and $midlopts be passed to GetOptions() as references?

    If you want to allow unspecified options to not cause warnings/errors, use the 'pass_through' option on Getopt::Long::Configure(), but that will leave the unspecified options in @ARGV, so if you want to remove them from @ARGV, you could also use Getopt::Std like so:

    # Configure here or with Getopt::Long::Configure() use Getopt::Long qw(:config pass_through); use Getopt::Std; my ($verbose, @linkfiles, $RCfile, $fixtarget, $midlopts); GetOptions ( 'help|?|h' => \&show_options, 'verbose!' => \$verbose, 'v' => \$verbose, 'L=s' => \@linkfiles, 'RC=s' => $RCfile, 'fixtarget!' => $fixtarget, 'midlopts=s' => $midlopts ) or die; # If you don't want '$opt_*' variables # springing into existence, supply a hashref to getopt. # Of course there's an ambiguity about whether # or not your 'bad' options are supposed to take an # argument, so there isn't really any perfect solution here. my %other_opts; getopt('', \%other_opts); print "ARGV: @ARGV\n";
Re: Error inside Getopt::Long
by bluto (Curate) on Oct 12, 2001 at 22:56 UTC
    I think there is a bug. It looks like it's complaining about your 'L=s' line. If I change the name to something else (like a lowercase 'l') it works ok. After looking at the .pm file, it looks like $L is used internally so perhaps there is some kind of conflict there?

    FWIW, I also get other errors trying your code above unless I put '\' in front of the last 3 scalars. Of course perhaps you are passing in references inside of them...

    bluto

(bbfu) (~no errors) Re: Error inside Getopt::Long
by bbfu (Curate) on Oct 13, 2001 at 10:10 UTC

    Other than $RCfile et. al not being passed by reference (as was already mentioned), I ran your code and got no errors.

    I'm running Getopt::Long version 2.25 on ActiveState perl v5.6.1. Perhaps this is a newer/older(?) version of Getopt::Long than you're running...?

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.