On Tue, Aug 23, 2011 at 5:53 PM, Emeka <emekami...@gmail.com> wrote:
> Hello All,
>
> Why shouldn't this work?
*snip*
> $result = GetOptions("age=i" => $age);

You should always try to explain the results you expect and what you
are getting instead. I had a hard time understanding what your problem
was just from reading your message. :)

It looks like your problem is passing the value of $age instead of a
reference to $age. In order for the Getopt::Long module to modify your
$age variable it needs a reference to it:

use strict;
use warnings;

use Getopt::Long;

my $age;

my %opts = ('age=i' => \$age);

GetOptions(%opts) or exit 1;

if(defined $age)
{
    print "You specified '$age' years";
}

__END__

You can see perlref and perlreftut to learn about references. You
should also be using 'strict' and 'warnings' (to possibly save Shlomi
a breath ;).


-- 
Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to