Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

how to use getOptions()

by prjain (Initiate)
on Mar 11, 2012 at 19:29 UTC ( #959001=perlquestion: print w/ replies, xml ) Need Help??
prjain has asked for the wisdom of the Perl Monks concerning the following question:

my $NAME; my $mobile; my $place; my $email; GetOptions ('name' => \$NAME,'mobile' =>\$mobile,'place' =>\$place,'em +ail' => \$email); print"$$NAME\n,$$mobile"; #$Contacts->findByName("$$NAME") if defined $$NAME;
Hello All,
In The above code no value is getting saved in variable $$NAME,because of which the function findByName also not working.As by running the command "perl test.pl --name xyz" I m getting no output while it should print xyz. Please suggest me why I am nt getting the appropriate o/p. Your valuable suggestion will help me a lot. Thanks in advance !!

Comment on how to use getOptions()
Select or Download Code
Re: how to use getOptions()
by choroba (Abbot) on Mar 11, 2012 at 20:03 UTC
Re: how to use getOptions()
by bitingduck (Friar) on Mar 11, 2012 at 20:30 UTC

    Try this

    #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $name; my $mobile; GetOptions ("name=s" => \$name,"mobile=s" =>\$mobile); print "$name\n$mobile\n";

    I sorted it out by using search to find this node: Examples for using Getopt::Long and poking about a bit. I cut out some of your parameters for convenience.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-08-31 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls