in reply to Getopt Behavior

Note that this is a non-standard way of doing command line options. That's why Getopt::Long is having trouble recognizing what you want to do. You may have better luck changing the syntax of your script so that it supports something like this:
$ script --id="1.0.0.1 1.0.0.2 1.0.0.3" # split the resulting variable on spaces $ cat >id.dat 1.0.0.1 1.0.0.2 1.0.0.3 $ script --id=@id.dat
In addition, if your script takes no "filename"-like arguments (arguments not preceeded by an option), consider making IP addresses an optional argument in this respect:
Usage: script.pl [-abcde] [ip_address [ip_address ...]]
Or, if your script does depend on, say, one additional argument, consider putting that in a flag, either making that option mandatory or using a suitable default (like stdin for a file), or just add it to the list of non-option arguments:
Usage: script.pl [-abcde] -f filename [ip_address [ip_address ...]] Usage: script.pl [-abcde] filename [ip_address [ip_address ...]]
Multiple arguments after a single option tag is kind of strange for people used to "standard" command line options for scripts and utilities. I would think about re-working the interface instead of trying to force Getopt to play by these other rules.

Replies are listed 'Best First'.
(Guildenstern) Re: Re: Getopt Behavior
by Guildenstern (Deacon) on Dec 06, 2000 at 01:15 UTC
    Non-standard? Getopt::Long supports this with no problems. Here's a snippet from the POD:
    Example of using variable references: $ret = GetOptions ('foo=s', \$foo, 'bar=i', 'ar=s', \@ar); With command line options ``-foo blech -bar 24 -ar xx -ar yy'' this wi +ll result in: $foo = 'blech' $opt_bar = 24 @ar = ('xx','yy')

    Looks to me like Getopt should have no problem with the original question. gaspodethewonderdog just needs to change the variable into a reference.

    Update: MeowChow is right - the example does use the -ar multiple times instead of just once. However, I do know that it can be done, since I have a working example.

    Guildenstern
    Negaterd character class uber alles!
      In this example, the -ar switch must be specified once for each list element, which is exactly what he wants to avoid. He's looking for a syntax which will understand: -foo blech -bar 24 -ar xx yy