in reply to Executing data based on command line arguments

I recommend using a module for starters. See How to check for the command line option entered?
  • Comment on Re: Executing data based on command line arguments

Replies are listed 'Best First'.
Re^2: Executing data based on command line arguments
by iphone (Beadle) on Dec 15, 2010 at 04:46 UTC

    I know how to check command line options,let me be explicit in my query again.Lets use the below sample code. In the below code

    1."print $line"should get executed no matter what (even if the option is not c),but 2. when option is "c"am checking for line in @array and then printing $line.

    if ($options(C) && grep /line/,@array) { print $line; }

    I know we can do the following,but how do I satisfy both conditions without using if-else,as an example I gave print $line,there are many more instructions in my script which i dont want to repeat

    if ($options(C) && grep /line/,@array) { print $line; } else #when option "c" is not given { print $line; }
      if ($options{foo} and satisfy_bar()) { poit(); } if (not $options{foo}) { narf(); }
      I think you can get your desired result by doing something like:
      if( ! $option{c} || grep /line/, @array ) { print $line; }