Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

process options which require two accompanying arguments

Posted on 1998-08-18
1
Medium Priority
?
215 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans

688 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