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

I was given some perl code to run and it doesn't run on our Linux system. The offending part of the code appears to be {,}.

It's used in this GetOptions 'call':

<code> GetOptions("h|help!","c|consistent!","s|sum!","threshold:f" => \$thresh old,"junk_files=s{,}" => \@junk_files); <code>

I get this error:

Error in option spec: "junk_files=s{,}"

I've tried changing the {,} to @, as below:

<code> GetOptions("h|help!","c|consistent!","s|sum!","threshold:f" => \$threshold,"junk_files=s@" => \@junk_files); <code>

It now reads the 1st file but no others. Any suggestions on how to handle the {,} ?

Thanks.

Replies are listed 'Best First'.
Re: {,} in GetOptions produces error
by Tux (Canon) on Apr 01, 2011 at 06:14 UTC

    That looked totally wrong. (and your end-tags miss a / (/code instead of just code).

    sub usage { my $err = shift and select STDERR; print "usage: $0 ...\n"; exit $err; } # usage use Getopt::Long qw(:config bundling); my $be_consistent = 0; my $sum = 0; my $threshold = 0.0; my @junk_files; GetOptions ( "h|help" => sub { usage (0) }, "c|consistent!" => \$be_consistent, "s|sum!" => \$sum, "threshold:f" => \$threshold, "junk_files=s" => \@junk_files, ) or usage (1);

    As suggested, you should read the manual.

    As a side note, I have no idea what --no-help would do :)


    Enjoy, Have FUN! H.Merijn
Re: {,} in GetOptions produces error
by ikegami (Patriarch) on Apr 01, 2011 at 06:42 UTC
    Aside from all the other errors, it sounds like the version of Getopt::Long you have installed doesn't support s{,}, a rather new addition.

      It was added in version 2.35, released on 28-Apr-2005:

      Changes in version 2.35 ----------------------- : * Options can take multiple values at once. E.g., --coordinates 52.2 16.4 --rgbcolor 255 255 149 To handle the above command line, the following call to GetOptions can be used: GetOptions('coordinates=f{2}' => \@coor, 'rgbcolor=i{3}' => \@colo +r); You can specify the minimum and maximum number of values desired. The syntax for this is similar to that of regular expression patterns: { min , max }.

      I wasn't even considering people using that old a version. You're probably right.


      Enjoy, Have FUN! H.Merijn
Re: {,} in GetOptions produces error (experimental)
by toolic (Bishop) on Apr 01, 2011 at 12:49 UTC
    Here is a quote from the current (perl 5.12.2) Getopt::Long:
    Warning: What follows is an experimental feature.
    Others have pointed out why you may be getting an error. This quote should weigh into your decision as to whether you want to use s{,} or not. I interpret "experimental" as meaning it may not be well-tested or reliable, or even that it may be removed in a future release.
Re: {,} in GetOptions produces error
by Anonymous Monk on Apr 01, 2011 at 03:53 UTC