Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Using getopt::Long

by madM (Beadle)
on Mar 12, 2014 at 20:04 UTC ( [id://1078083]=perlquestion: print w/replies, xml ) Need Help??

madM has asked for the wisdom of the Perl Monks concerning the following question:

Hi.. i was wondering if what im doing is right.. If i have some options and i just want to call subroutines with the option.. is this right?
GetOptions ( 'opta=s' => \&a, 'optb=s' => \&b, 'optc=s' => \&c, )or die "not working: $!\n"; sub a { blabla } sub b { blabla } sub c { blabla }
and another quick question... is it posible to call a subroutine in another subroutine with getopt:long?

Replies are listed 'Best First'.
Re: Using getopt::Long
by runrig (Abbot) on Mar 12, 2014 at 20:12 UTC
    i just want to call subroutines with the option.. is this right?
    Yes, that's how you do it. Did you try it? What problems are you having with it. It would likely be quicker to try such a thing than to ask here and wait for an answer.
    is it posible to call a subroutine in another subroutine with getopt:long?
    What do you mean? I'm not sure what you are talking about. But it might be quicker to try it and then ask for help with any problems you might have.
Re: Using Getopt::Long
by toolic (Bishop) on Mar 12, 2014 at 20:09 UTC
Re: Using getopt::Long
by TomDLux (Vicar) on Mar 13, 2014 at 02:58 UTC

    on your machine at home/work, you can type into a terminal window / command window:

    perlodc Getopt::Long

    to view the documentation in the file. ( I don't run windows, so there may be more to it on those platforms). Or you can browse to metacpan.org, search for the module you're interested in, and read the documentation there. It describes exactly the situation you're asking about.

    I suspect you're thinking about interrupt handlers, where you're advised to keep the code short, not call too many other routines, to avoid complications. Nothing like that here, Your program can call A, B, or C, do various work for hours, and never even return to the main. It would be kind of perverted, but you could :-)

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re: Using getopt::Long
by Discipulus (Canon) on Mar 13, 2014 at 08:08 UTC
    only few things to add: read this very good old node (i discoverd it yesterday..) because if you are doing the effort to use GetOpt::Long, may be easy and usefull add automatical help and man to your program, bringing it to a superior usability and durability.

    Also be sure to read the above mentioned docs because, being that module very powerfull, it can sometimes surpise you.
    In fact, as you are using a sub to be tricked by argouments and options, maybe you have to know that GetOpt::Long is consuming @ARGV during the GetOptions call or the fact that you can still have somethng in @ARGV using the double dash --

    Hth
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1078083]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found