Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 (Bishop) 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 examining the Monastery: (6)
As of 2018-04-19 17:48 GMT
Find Nodes?
    Voting Booth?