Why does the same Getopt::Long code work differently in different programs?

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 18:31 UTC
Read the original article Hit count: 330

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 you're 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 advance!

I've solved this.....

and btw it's a VERY clear question (so why the downvotes)? I'll state it again:

What would cause the identical GetOptions block to work in these 2 ways:

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

see how clear?

Maybe you guys should think about it as if it were a TEST!

© Stack Overflow or respective owner

Related posts about perl