perlgetopt-longcommandargument

How do I send a value that starts with a dash to Getopt::Long?


I've got a client-side script I'm making that communicates with GNU-FTP. I want to be able to send it a custom argument on the command line, so I've created an argument --ftp-args

This is what it looks like

GetOptions(
  .. redacted stuff..
  "ftp-args=s%" => \$FTP_ARGS
) or die("Error in command line arguments\n");

However, whenever I try to call it I get an error,

$ ./script/dm-ftp360 --ftp-args="-E"
Option ftp-args, key "-E", requires a value
Error in command line arguments

Is it possible to get around this, and make this possible?


Solution

  • You've specified s% - defining an option that specifies hash entries. That implies a form key=value for each argument to the option. But you've only specified -E. The error message is about the missing =value part, not the leading -.

    Perhaps use s@ instead to ingest a set of simple options? Or give an empty value using "-E=" if you need to separate the keys and values before passing them to ftp.