dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

Getopt::Long has two usages - either by passing in variable references or a hashref within which to have GetOptions() set keys and values. Using the first method allows for multiple entries for the same key (using an arrayref). However, reading the perldoc for Getopt::Long doesn't tell me how to allow for multiple entries of the same key using the hashref method.

As I'm working with some 10-12 options, I need to use the hashref method. (Don't ask - not my design.)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
(tye)Re: Using Getopt::Long
by tye (Sage) on Mar 13, 2002 at 17:14 UTC

    Quoting the referenced documentation:

    For array options, a reference to an array is used, e.g.:
    %optctl = (); GetOptions (\%optctl, "sizes=i@");

    So you append '@' to the specification. Once I saw that, I searched for @ and found the documentation for this under the "Compatability" section.

    Note that I'd use single quotes or back-slash the @ if for no other reason than to make the intent of a literal @ clear.

            - tye (but my friends call me "Tye")
Re: Using Getopt::Long
by dmmiller2k (Chaplain) on Mar 13, 2002 at 17:38 UTC

    ++tye.

    The '@' suffix to the parameter type specification should always be there when you want to accept multiple entries for the same key (command-line option), but when using Getopt::Long with variable references, an arrayref makes it redundant and allows it to be omitted, as a shortcut (!).

    dmm