Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: deadly7 on June 09, 2011, 06:25:44 PM

Title: Perl Getopts question
Post by: deadly7 on June 09, 2011, 06:25:44 PM
Relevant code:


use strict;
use Getopt::Std;
my %options;
getopts('hdPp:remno', \%options);


I want to call the help sub [which displays a help message] if either of the two following conditions are met:
1. the h flag is specified
2. getopts returns NO command-line options.

Here's what I've tried, with various errors
Quotehelp() if($options{'h'} || !defined \%options || !defined $options);

Anybody know what I'm doing wrong? Googling hasn't returned what I'm looking for. :-\
Title: Re: Perl Getopts question
Post by: iago on June 09, 2011, 07:17:49 PM
try isempty(%options) perhaps?
Title: Re: Perl Getopts question
Post by: Sidoh on June 09, 2011, 09:33:05 PM
Probably want something like

help() if (! keys %options || defined $options{'h'});
Title: Re: Perl Getopts question
Post by: deadly7 on June 10, 2011, 01:43:21 PM
Quote from: Sidoh on June 09, 2011, 09:33:05 PM
Probably want something like

help() if (! keys %options || defined $options{'h'});
<3