Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 --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 !!

Replies are listed 'Best First'.
Re: how to use getOptions()
by bitingduck (Chaplain) 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.

Re: how to use getOptions()
by choroba (Chancellor) on Mar 11, 2012 at 20:03 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://959001]
Approved by planetscape
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2017-07-24 08:50 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (348 votes). Check out past polls.