Solved

process options which require two accompanying arguments

Posted on 1998-08-18
1
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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 …
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…
Six Sigma Control Plans

623 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