Author Topic: Perl Getopts question  (Read 5772 times)

0 Members and 1 Guest are viewing this topic.

Offline deadly7

  • 42
  • x86
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Perl Getopts question
« on: June 09, 2011, 06:25:44 pm »
Relevant code:

Code: [Select]
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
Quote
help() if($options{'h'} || !defined \%options || !defined $options);

Anybody know what I'm doing wrong? Googling hasn't returned what I'm looking for. :-\
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Perl Getopts question
« Reply #1 on: June 09, 2011, 07:17:49 pm »
try isempty(%options) perhaps?

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Perl Getopts question
« Reply #2 on: June 09, 2011, 09:33:05 pm »
Probably want something like

Code: [Select]
help() if (! keys %options || defined $options{'h'});

Offline deadly7

  • 42
  • x86
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: Perl Getopts question
« Reply #3 on: June 10, 2011, 01:43:21 pm »
Probably want something like

Code: [Select]
help() if (! keys %options || defined $options{'h'});
<3
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine