Solved

process options which require two accompanying arguments

Posted on 1998-08-18
1
205 Views
Last Modified: 2010-03-05
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];
}

.............
0
Comment
Question by:rongz
1 Comment
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1204379
$errs = undef;
while (@ARGV) {
   getopts("f:o:");
   if (defined($opt_f) && !defined($opt_f2)) {
       $opt_f2 = shift(@ARGV);
   } else {
       $errs = shift(@ARGV);
       print "Bad option: $errs\n";
}
exit if defined($errs);
$other = defined($opt_o) ? $opt_o : 'other';
$file1 = defined($opt_f) ? $opt_f : 'name1';
$file2 = definend($opt_f2) ? $opt_f2 : 'name2';

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question