?
Solved

Getopt::long samples

Posted on 2007-10-10
3
Medium Priority
?
1,023 Views
Last Modified: 2008-01-09
I'm trying to get some simple Getopt::Long examples going, but nada  so far.  

For example;
c:\>script.pl --name=Jerry
Input name is Jerry

# script.pl code
use Getopt::Long;
 
# read options
$result = GetOptions ("name=s" => $name);  

# print value
print "Input name is $name\n";
exit;

or


c:\>script2.pl --base=10 --height=20
Base = 10
Height = 20
Area = 100

# script2.pl code
use Getopt::Long;

# read options into hash
$result = GetOptions (%options, "base=i", "height=i");  

# print hash values
print "Base = " . $options{'base'} . "\n";
print "Height = " . $options{'height'} . "\n";
print "Area = " .  0.5 * $options{'base'} * $options{'height'} . "\n";
exit;


0
Comment
Question by:Marketing_Insists
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 20053806
$result = GetOptions ("name=s" => $name);  


should be

$result = GetOptions ("name=s" => \$name);  
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20053811
$result = GetOptions (%options, "base=i", "height=i");  

should be

$result = GetOptions (\%options, "base=i", "height=i");  
0
 

Author Comment

by:Marketing_Insists
ID: 20097214
Thanks!, That was it.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question