Hi, Monks -

I came across a very, very basic observation today which illustrated to me that I am lacking some basic understanding on Perl's behaviour in a Unix-family operating system environment. My apologies therefore for bothering you with this question.

So far, I thought that piping some input into a Perl programme was the same as handing over that input as an invocation argument to the programme. I found, however, that this is not the case:

Here's my test programme test.pl:
#! /usr/bin/perl -w print $ARGV[0];
My oberservations were:
$ test.pl Hello Hello
while
echo "Hello" | test.pl Use of uninitialized value in print at ./test.pl line 2

I thought that the pipe was passing on the arguments to the next element in the pipe via STDIN ... can anybody therefore please explain to me why this is not working?

Thanks for your help in advance!

Cheers - Pat

In reply to Difference between piped-in and invocation arguments to a Perl script? by pat_mc

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.