Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found