On Tuesday 11 December 2007 16:53, protoplasm wrote:
>
> I'm messing around with Getopt and have a set of arguments that can
> be passed to the program. I am new to perl and am unaware of how to
> resolve the error while keeping 'use warnings;' enabled. Any help
> would be greatly appreciated.
>
> Code:
>
> ==============================================
> #!/opt/local/bin/perl
>
> use Getopt::Long;
>
> #use diagnostics;
> use strict;
> use warnings;
>
> my $opts_hash;
> my %opts_hash = ();
>
> if (@ARGV < 1)
> {
>       print "argv is less than 1!\n";
>       print "Exiting...\n";
>       exit;
> }
>
> GetOptions( 'all' => \$opts_hash{allTests},
>       'CbcDec' => \$opts_hash{CbcDec}, 'CbcEnc' => \$opts_hash{CbcEnc},
>       'CfbDec' => \$opts_hash{CfbDec}, 'CfbEnc' => \$opts_hash{CfbEnc},
>       'CtrDec' => \$opts_hash{CtrDec}, 'CtrEnc' => \$opts_hash{CtrEnc},
>       'EcbDec' => \$opts_hash{EcbDec}, 'EcbEnc' => \$opts_hash{EcbEnc},
>       'OfbDec' => \$opts_hash{OfbDec}, 'OfbEnc' => \$opts_hash{OfbEnc},
>       'Sha1Test' => \$opts_hash{Sha1Test}
> );

Perl will autovivify the hash keys because you are passing the hash 
value references to GetOptions.  An alternative way that will not 
autovivify all the keys is:

GetOptions( \my %opts_hash,
    'allTests', 'CbcDec', 'CbcEnc', 'CfbDec', 'CfbEnc', 'CtrDec',
    'CtrEnc', 'EcbDec', 'EcbEnc', 'OfbDec', 'OfbEnc', 'Sha1Test' );


> foreach (keys %opts_hash)
> {
>       if ( $opts_hash{$_} == 0 )

perldoc -f defined


>       {
>               next;
>       }
>       elsif ( $opts_hash{$_} == 1 )
>       {
>               print "$_ = $opts_hash{$_}\n";
>       }
> }
> ==============================================
>
> naiad:~/workspace $ ./debug2.pl --CbcDec
> Use of uninitialized value in numeric eq (==) at ./debug2.pl line 32.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to