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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.