I want run program with options --help and without options. In both cases i want that my programm show me HELP MESSAGE (see Condition 1). But i need aslo to set arguments like this ./install.pl --config main.cfg --setup (see Condition 2). But this not work, because @ARGV always zero and "Condition 2" never to be. I read that GetOpt ignor (or replace) standart ARGV. You can suggest me check "--config" and "--setup" in the "Condition 1". But I would like to avoid it. How to check for "--config main.cfg" when the user can execute the program with an empty argument? Thanks.#!/usr/bin/perl use strict; use feature qw(say); use warnings; use utf8; use Getopt::Long; my ($helpCmdArgv, $configCmdArgv, $setupCmdArgv, $servertypeCmdArgv); my $cmdArgsResult; $cmdArgsResult = GetOptions ( "help" => \$helpCmdArgv, "config=s" => \$configCmdArgv, "setup" => \$setupCmdArgv, "servertype=s" => \$servertypeCmdArgv ); # Condition 1 if ( (@ARGV eq 0) or ($helpCmdArgv eq 1) ) { say scalar(@ARGV); &Help; }; # Condition 2 say scalar(@ARGV); ($configCmdArgv) ? say 'Custom config' : say 'Default config'; sub Help { print <<HELP; Avliable options: --config - Main config file --setup - Just install files. --servertype - Server type, where: |-> db - Database server; |-> app - Application server; HELP exit 1; };
In reply to GetOpt::Long empty ARGV by Pazitiff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |