Hi monks,
when i use Getopt::Long in a perl file and call the perl file alone it works but if i call the perl file within a shell script passing all the command line options to the perl file they wont work..... down is the example code
use Getopt::Long; my %options; $ret=GetOptions( "i" => \$options{i}, "o=s" => \$options{o}, "p=s" => \$options{p}, "h" => \$options{h} ); if ( $ret=="" || exists $options{'h'} || !@ARGV) { print " \nCommand line options: -i interactive -o file give a file -h help -p value personal exit; } else { if (exists $options{i}) { print "i is enabled\n"; } if (exists $options{o}) { print "o is enabled file is $options{o}\n"; } if (exists $options{p}) { print "p is enabled value is $options{p}\n"; } }
now the line in shell script is
perl ex.pl $*
here $* has the command line arguments
if the ex.pl is run with perl on the shell prompt i get proper output. but when i run the shell script with the same command line arguments i dont get the desired output....is it the problem with "exists" or the getopts
Edited by davido: Moved from PerlMonks Discussion to Seekers of Perl Wisdom, and formatted with paragraph and code tags.
janitored by ybiC: Correct module typo in title and node contents, "getops:long", for better site search results
In reply to problem with Getopt::Long by syedtoah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |