We help IT Professionals succeed at work.

Getopt::long samples

Marketing_Insists
on
1,042 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;


Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007

Commented:
$result = GetOptions (%options, "base=i", "height=i");  

should be

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

Author

Commented:
Thanks!, That was it.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.