Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

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


I'm not sure what's going on here with this. I've used this method for command line args over and over again
and suddenly now it doesn't seem to be working correctly...?

I'm simply passing in 2 IP Addresses to the script but they are not being assigned to the Variables and
I can't seem to figure out why...


COMMAND:
./test_perl.pl ipAddr=192.168.1.1 server=192.168.5.1

CODE:
#!/usr/bin/perl use warnings; use strict; use File::Copy; use Getopt::Long; use Term::ANSIColor qw(:constants); $Term::ANSIColor::AUTORESET = 1; # TEST --> Print the Args so we can see that they are being passed: print "\@ARGV: \"@ARGV\"\n\n"; my $srv_address; my $ip_address; if ( @ARGV > 0 ) { print "GETTING OPTIONS...\n\n"; GetOptions('ipAddr=s' => \$ip_address, 'server=s' => \$srv_address ); } print BOLD " IP Address = " . RESET "$ip_address\n"; print BOLD "SERVER Address = " . RESET "$srv_address\n"; exit 0;


OUTPUT:
@ARGV: "ipAddr=192.168.5.196 server=192.168.5.1" GETTING OPTIONS... Use of uninitialized value $ip_address in concatenation (.) or string +at ./test_diff.pl line 25. IP Address = Use of uninitialized value $srv_address in concatenation (.) or string + at ./test_diff.pl line 26. SRV Address =


Does anyone see what I'm doing wrong here...?
Any thoughts would be great!



Thanks in Advance,
Matt



In reply to GetOptions Function NOT Assign CLI Args to Variables? by mmartin

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 having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found