IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Getoptions, pod2usage, oh my!
I'm puzzled as to why this fragment isn't behaving as expected:
# Process command-line arguments\nmy $pco_dir = '';\nmy $rcc_dir = '';\nmy $out_dir = '';\nGetOptions ("pco=s" => \\$pco_dir,\n            "rcc=s" => \\$rcc_dir,\n            "out=s" => \\$out_dir,  \n            "debug" => \\$debug) or pod2usage(2);


The intention is that if any option other than "--debug" is omitted, then I'll print the bit of my pod documentation.

Only I don't; I carry on past this point.

Pod documentation is hunkydory; I tested this with pod2html.

Have I missed something?


Peter
[link|http://www.no2id.net/|Don't Let The Terrorists Win]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Interim solution
pod2usage(1) unless $pco_dir && $rcc_dir && $out_dir;

I'd really rather specify in the Getoptions call that those arguments are all mandatory.


Peter
[link|http://www.no2id.net/|Don't Let The Terrorists Win]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Re: Interim solution
use Getopt::Long (?)

or require arguments on the command line if they're required.

[link|http://perldoc.perl.org/Getopt/Long.html| Getopt::Long ]
Expand Edited by Simon_Jester Nov. 1, 2005, 09:38:00 AM EST
Expand Edited by Simon_Jester Nov. 1, 2005, 09:39:09 AM EST
New I'm already using Getopt::Long.


Peter
[link|http://www.no2id.net/|Don't Let The Terrorists Win]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Where does it say that you should expect that?
Getopt::Long doesn't know which options are required. It just knows whether it managed to process the command-line options.

BTW a random hint. I like to do this:
\nGetOptions(\n  "foo=s"   => \\ my $foo,\n  "bar=i"   => \\ my $bar,\n);\n

if I'm not trying to initialize defaults.

If you want a command-line processor that can figure out required arguments, then I'd suggest Getopt::Declare or Getopt::Euclid. (The latter looks more interesting to me.) But note that since I work in a code-base that has established conventions around Getopt::Long, I have not bothered experimenting with those.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
     Getoptions, pod2usage, oh my! - (pwhysall) - (4)
         Interim solution - (pwhysall) - (2)
             Re: Interim solution - (Simon_Jester) - (1)
                 I'm already using Getopt::Long. -NT - (pwhysall)
         Where does it say that you should expect that? - (ben_tilly)

Memorably described by colleagues as someone who would "unplug you from life support so she could charge her phone."
46 ms