perl Getopt::Long madness

Posted by ennuikiller on Stack Overflow See other posts from Stack Overflow or by ennuikiller
Published on 2010-03-22T15:16:17Z Indexed on 2010/03/22 15:31 UTC
Read the original article Hit count: 458

Filed under:
|

The following code works in one script yet in another only works if a specify the "--" end of options flag before specifying an option:

my $opt;
GetOptions(
    'help|h' =>
    sub { usage("you want help?? hahaha, hopefully your not serious!!"); },
    'file|f=s' => \$opt->{FILE},
    'report|r' => \$opt->{REPORT},
) or usage("Bad Options");

In other words, the same code words in good.pl and bad.pl like so:

good.pl -f  
bad.pl -- -f

If I try

bad.pl -f 

I get "unknown option:f"

Anyone have any clue as to what can cause this behavior? Thanks in advnace!

© Stack Overflow or respective owner

Related posts about perl

Related posts about getopt-long