Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day NewLondonPerl1,

This looks like a simple assignment to me:

#!/usr/bin/env perl use 5.010; use strict; use warnings; use Getopt::Long; my %opts; GetOptions(\%opts, qw{conf|c=s}); my $master_conf = $opts{conf}; say $master_conf;

Here it is in action:

$ pm_getopt_var.pl --conf conf_value conf_value

Depending on where you do the assignment, you may want:

$master_conf = $opts->{conf};

The only place in your posted code that you mention $master_conf is in what appears to be a standalone piece of code with no obvious connection to other parts of your script:

my $json_data = extract_json("$master_conf");

Where were you intending to declare this variable? Where were you intending to assign it a value? I suspect one problem you have here is that you can't see the wood for the trees: probably 80% of the code you've posted has nothing to do with the issue at hand. Try making a simple, cut-down version of the script; when that's working, add in more complexity.

From the code you've posted, my best guess as to what you want is something like this:

# shebang and use <whatever> lines here my $opts = getoptions(); my $master_conf = $opts->{conf}; # do something with $master_conf here (validation perhaps) my $json_data = extract_json($master_conf); my $decoded_json_obj = decode_json($json_data); # do something with $decoded_json_obj here # subroutine definitions here

-- Ken


In reply to Accessing Getopt::Long values by kcott
in thread Using getopt::long and how to use the value of one of the command line options in a subroutine by NewLondonPerl1

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 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?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-18 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found