Well, one problem is that you are first calling GetOptions, and then asking that @ARGV not be empty... however, the way that GetOptions works is to remove values from @ARGV. So if all that is contained in @ARGV are -options, then after GetOptions, they'll have all been removed from @ARGV, and @ARGV will be empty.

Another problem (that isn't with your Getopt::Long), is with your shell scripting. If you want to pass all arguments through to a command in a shell script, it's done like:

command "$@"
rather than
command $*
The difference can be demonstrated if you just take this simple shell script (lets call it "test.sh"):
#!/bin/sh perl -e "use Data::Dumper; print Dumper \@ARGV" $*
and call it with some arguments that will demonstrate why this breaks:
[sstone@ernie1 scratch]$ sh test.sh 1 2 "3 and more stuff" $VAR1 = [ 1, 2, 3, 'and', 'more', 'stuff' ]; [sstone@ernie1 scratch]$
but if we change test.sh to:
#!/bin/sh perl -e "use Data::Dumper; print Dumper \@ARGV" "$@"
and run it the same way:
[sstone@ernie1 scratch]$ sh test.sh 1 2 "3 and more stuff" $VAR1 = [ 1, 2, '3 and more stuff' ]; [sstone@ernie1 scratch]$
The difference being that "$@" will preserve the arg list as a list, whereas $* will flatten it all into a string (basically just like join(" ",@ARGV)), and then split it on whitespace... so if you had args with whitespace in them it would get all messed up.

At the very least, that's a couple of things that might be causing you problems.

------------ :Wq Not an editor command: Wq

In reply to Re: problem with Getopt::Long by etcshadow
in thread problem with Getopt::Long by syedtoah

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.