On 09/02/2011 21:52, gry wrote:
[[v5.8.8 built for x86_64-linux-thread-multi]
#!/usr/bin/perl -W
use Getopt::Long;
my $dml = 0;
my $iterations = 10;
my %options = ("dml!" => \$dml,
"iterations=i" => \$iterations);
GetOptions(%options) || die "bad options";
printf "dml=$dml\n";
print %options;
foreach $key (sort keys %options) {
printf "$key: $options{$key}\n";}
This script prints:
dml=0
dml!SCALAR(0xa461540)iterations=iSCALAR(0xa461560)dml!:
SCALAR(0xa461540)
iterations=i: SCALAR(0xa461560)
How can I get readable output of my getopt options without manually
enumerating them?
You are confused and using a mixture of two different ways of specifying
the expected parameters. If you want the values in a hash then you
should code as below.
Please /always/ use strict.
HTH,
Rob
use strict;
use warnings;
use Getopt::Long;
my %options = (
dml => 0,
iterations => 10,
);
GetOptions \%options, 'dml!', 'iterations=i' or die 'Bad command line
options';
foreach my $key (sort keys %options) {
print "$key: $options{$key}\n";
}
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/