There is another problem with this bit of logic: If you want a default for the first argument ($based_on), you still have to specify it:
mycode.pl tp 5
if you do not, the script will assume the value you passed for $top is your $based_on, eg:
mycode.pl 5
So this logic model does not make sense. You can differentiate between the arguments for example by putting a '-' in front of the $based_on argument, or if the argument passed to $top is always numeric, you can use that as well. Best is to ensure your arguments are exactly right:
1 #!/usr/bin/perl -w 2 3 use strict; 4 5 my $based_on = ($ARGV[0] && ($ARGV[0] =~/tp|sn/)) ? shift : 't +p'; 6 my $top = ($ARGV[0] && ($ARGV[0] =~ /[1-5]/)) ? shift : 1; 7 scalar(@ARGV) && die "Arguments not parsed: " . join(':', @ARG +V) . "\n"; 8 9 print "$based_on $top\n";
-Reenen

In reply to Re: Ternary Operator for Multiple Arguments Passing by Anonymous Monk
in thread Ternary Operator for Multiple Arguments Passing by neversaint

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.