Hi everyone, I'm trying to handle the possibility that a script executes based on following scenarios 1> no arguments are passed to the script 2> arguments maybe passed from command line 3> piped data is passed to a Perl script from file.
if ($#ARGV == -1){..#no arguments passed.} elsif ($#ARGV == 1){..# arguments passed from command line.} elsif (-t STDIN and not @ARGV){..#piped inputs are supplied....do this +} else {default: usage error}
The first two scenarios works fine.The piped input scenario works good if i just use it as a seperate perl script nd do test.pl < input.txt But when i try to combine it with above two scenarios it always enters the first case. I read somewhere that -t option is used to check if handle is open to tty and since piped inputs are supplied through stdin i thought this works but somehow it doesnt. I also tried using (*stdin) in the third case but it messes up the other two options ..Any sugestions ? - Thanks Ram

In reply to Using PIped-in and invocation arguments in same script by justkar4u

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.