roboticus: Thanks a lot! Based upon my understanding of your program above, I wrote this small one:
#!/usr/bin/perl -w open ($FH,'| sort -n') or die($!); while(<ARGV>){ print $FH $_; } close $FH;
Thanks again for "__DATA__" as well. There is one thing I would like mention: I used to write FH instead of $FH in open() as the file-handler. But both of them work. I did not know it. Please have a look at this:
[demo@localhost Perl]$ cat bar.pl #!/usr/bin/perl -w open (FH,'| sort') or die($!); $count=0; while(<ARGV>){ print FH $_; print $count++ . "\n"; } close FH; [demo@localhost Perl]$ bar.pl words 0 1 2 3 4 A ABC a to z Buy Why
The line numbers are being printed out first and then the sorted list of the words. That means (this is what I understand now) that the data are being fed to the "sort" command which returns its result when all the input to it is fed.

In reply to Re^2: Filehandles and Input and Output Filters by devarishi
in thread Filehandles and Input and Output Filters by devarishi

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.