Solved

Using Getopt::Long to call one or more Subroutines..

Posted on 2006-10-20
1
305 Views
Last Modified: 2008-03-06
How do I use Getopt::Long to call one or more sub routines in my program?


__Code__

GetOptions( "one" => .....sub1().... ,
            "two"  => .....sub2()....,
             "three" => ....sub3().... );


sub sub1 {
print "sub one";
}

sub sub2{
print "sub two";
}

sub sub3 {
print "sub three";
}

__End Code__

Also I read in the Getopt::Long's perldoc that you need to use "Permute" to set a subroutine as default if no arguement is passed in the command line.  How would I make it so that subroutine sub1 is called when not arguement is given in the commandline.


















0
Comment
Question by:chinamox
[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 9

Accepted Solution

by:
Suhas . earned 450 total points
ID: 17782927
Hi chinamox,

use Getopt::Long;

GetOptions( "one" => sub { sub1() },
            "two"  => sub { sub2() },
             "three" => sub { sub3() } );


sub sub1 {
print "sub one\n";
}

sub sub2{
print "sub two\n";
}

sub sub3 {
print "sub three\n";
}


on command line,
$perl prog.pl -one
#prints
sub one
$perl prog.pl -one -two
#prints
sub one
sub two

Cheers!
Suhas
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

749 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