Link to home
Start Free TrialLog in
Avatar of rongz
rongz

asked on

process options which require two accompanying arguments

Hello,
I know Geopt::Std can process single-character option which require one accompanying argument. But my problem is i would  like to invok program with some options which need two accompanying arguments. Is there some way around this?

part of program:
# this program only works when invoke like
#              command [-o sth] [-f filename1 filename2]
# but not
#        command [-f filename1 filename2][-o sth]    
# because processing of @ARGV stops when an argument without # a leading - is encountered.

use Getopt::Std;
getopts("f:o:");

if(!defined($opt_o)){
   $opt_o="other";
}
$other=$opt_o;

if (!defined($opt_f){
   $file1="name1";
   $file2="name2";
}else{
   $file1=$opt_f;
  $file2=$ARGV[0];
}

.............
ASKER CERTIFIED SOLUTION
Avatar of b2pi
b2pi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial