Getopt::long samples

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;


Marketing_InsistsAsked:
Who is Participating?
 
TintinCommented:
$result = GetOptions ("name=s" => $name);  


should be

$result = GetOptions ("name=s" => \$name);  
0
 
TintinCommented:
$result = GetOptions (%options, "base=i", "height=i");  

should be

$result = GetOptions (\%options, "base=i", "height=i");  
0
 
Marketing_InsistsAuthor Commented:
Thanks!, That was it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.