This broke with:# define option names and defaults our $UNIQUE_OPT = q/unique/; our $FORCE_OPT = q/force/; our $VERBOSE_OPT = q/verbose/; our $OUTPUT_EXT_OPT = q/ext/; # create option specs for Getopt my @option_config = qw( $UNIQUE_OPT $FORCE_OPT $VERBOSE_OPT $OUTPUT_EXT_OPT=s ); # create option hash for Getopt my(%option, %option_config); foreach my $option_config ( @option_config ) { # copy $option_config to $option_name, keep only name of option ( my $option_name = $option_config ) =~ s/\W.*$//; # save a reference to the %option value in %option_config hash $option_config{$option_config} = \$option{$option_name}; } # process options GetOptions %option_config or usage(); if ( $option{$UNIQUE_OPT} and $option{$FORCE_OPT} ) { die "-$UNIQUE_OPT and -$FORCE_OPT are mutually exclusive." . " See $SCRIPT_NAME -help for syntax."; }
Due to the hour of the day, I sat and stared at this for some time, scanned through Getopt::Long, and scratched my head.C:\>perl myscript stuff Error in option spec: "$VERBOSE_OPT" Error in option spec: "$FORCE_OPT" Error in option spec: "$OUTPUT_EXT_OPT=s" Error in option spec: "$UNIQUE_OPT"
Finally it hit me -- qw doesn't interpolate, so things like $UNIQUE_OPT don't DWIM. The fix was:
which looks very similar to the rough equivalent of qw as found in perlop:my @option_config = split ' ', qq( $UNIQUE_OPT $FORCE_OPT $VERBOSE_OPT $OUTPUT_EXT_OPT=s );
In fact, it made me wonder if this DWIM:split(' ', q/STRING/);
:( Sadly, it doesn't.my @option_config = qw" $UNIQUE_OPT $FORCE_OPT $VERBOSE_OPT $OUTPUT_EXT_OPT=s ";
Anyone care to comment on whether this should or shouldn't make it into the language?
-QM
--
Quantum Mechanics: The dreams stuff is made of
In reply to qw "$string $string" doesn't interpolate by QM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |