in reply to How to execute perl script with options using Eclipse IDE?

Irrespective of any potential issues with Eclipse, your code most likely won't do what you want even when run from the normal command line.

GetOptions returns true if the arguments could successfully be parsed, so that's what you're testing in your subsequent if ($option) { ... }.

Maybe you meant to test if ($age) { ... } instead?  But then you shouldn't initialize the variable with 24, because that's a true value, too... (likewise for $name, of course)

Replies are listed 'Best First'.
Re^2: How to execute perl script with options using Eclipse IDE?
by Divakar (Sexton) on Nov 29, 2011 at 10:07 UTC
    use Getopt::Long; my $name; my $age; my $option=GetOptions("name"=>\$name,"age"=>\$age); print "the options are $option\n"; if ("$name") { print "the option given is divakar\n"; } if ("$age") { print "the option given is 24"; }
    I just tried as you said. but getting following error.
    the options are 1 Use of uninitialized value $name in string at C:/Diva Projects/Eclipse +/Scripts_Testing/getopt.pl line 8. Use of uninitialized value $age in string at C:/Diva Projects/Eclipse/ +Scripts_Testing/getopt.pl line 13.

      Just leave off the double quotes around "$name" and "$age" — they're useless here anyway.

      Interpolating an uninitialized variable into a string produces a warning (when warnings are enabled), while simply testing an unitialized variable for truth (i.e. if ($name) ... ) does not.