chinamox has asked for the wisdom of the Perl Monks concerning the following question:
I am new to Perl and trying to package some of my earlier programs into a new program as subroutines. I would like to use Getopt::Long to then specify which subroutines to run. So far I have something that looks kind of like this:
GetOptions( "one" => .....sub1().... , "two" => .....sub2()...., "three" => ....sub3().... ); sub sub1 { print "sub one"; } sub sub2{ print "sub two"; } sub sub3 { print "sub three"; }
I guess I could set each option equal to a $scalar like this:
GetOptions( "one" => $three, "two" => $two, "three" => $three );
I could then call the subroutines using simple if statements. However the last few weeks of working with Perl has led me to suspect that Perl programmers, being clever and brilliant people, have a direct way just calling the subroutines without using if statements at all. Could anyone confirm or dispell this suspicion?
Also I read in the Getopt::Long's perldoc that you need to use "Permute" to set a subroutine as default if no argument is passed in the command line. How would I make it so that subroutine sub1 is called when not argument is given in the command line. Could anyone point me towards an example?
Thank you all for your time and attention.
-mox
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Getopt::Long to call subroutines
by jdporter (Paladin) on Oct 22, 2006 at 04:25 UTC | |
by chinamox (Scribe) on Oct 22, 2006 at 05:18 UTC | |
by jdporter (Paladin) on Oct 22, 2006 at 13:32 UTC | |
by blazar (Canon) on Oct 22, 2006 at 16:25 UTC | |
by imp (Priest) on Oct 22, 2006 at 04:44 UTC | |
|
Re: Using Getopt::Long to call subroutines
by imp (Priest) on Oct 22, 2006 at 03:56 UTC | |
by chinamox (Scribe) on Oct 22, 2006 at 04:10 UTC | |
by imp (Priest) on Oct 22, 2006 at 04:19 UTC |