Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi,

I want to factor out the GetOptions(...) call into a library but have run into a few issues.
So here's what I want to do:

Main Program:
- create a hash
- create an array of parameters I want to read off the command line in the GetOptions(...) format (ie "home=s", "instance=s", fileSuffix:s", etc)
- pass a reference to the hash and array to the Util method encapsulating the GetOptions call

Util method w/GetOptions call:
Now this is where the problem is, I don't know how to format a string so it can fill in the hash.
I tried iterating over each entry in the array and calling GetOptions(...) individually, but on the first call, it tries to load up all the paramters and then on subsequent calls cannot find any paramters (since they've been consumed by the first call) (if this is wrong, please correct me as well).

So then I found another method where you can pass in a hash ref and the parameter you want.
- ie GetOptions( \%myHash, "home=s");

So I tried to pass in one huge string consisting of all the parameters I want
( ie GetOptions( \%myHash, "home=s,instance=s,fileSuffx:s") but that didn't work either (which didn't surprise me).

Any suggestions out there? Thanks a lot!!

In reply to Getopt::Long by david.shin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2022-01-19 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?