Monks
This has got to be in the silly easy category, but I can't think of it for the life of me and I can't get the right keywords in super search to show what I'm missing...
I'm wanting to process a series of files but rather than go...
-->process file1 file2 file3
...I want to be able to go some thing like
-->ls file* | process
I'm running on linux and was under the impression that if I piped data it would appear as command line arguments, but this does not seem to be the case, or at least I'm doing it wrong.
So writing a simple example(counting lines) the does the first case does not work for the second...
#!/usr/bin/perl use strict; use warnings; my $numargs = $#ARGV + 1; if ( $numargs == 0 ) { print "Incorrect number or arguments($numargs)...\nFormat: lin +es <file>\n\n"; exit(0); } my $t = 0; for my $f ( 0 .. $#ARGV ) { my $file = $ARGV[$f]; open FILE, "<$file" or die "Could not open file, $file : $!\n" +; my $c = 0; while (<FILE>) { $c++; $t++; } close (FILE); print "$c\n"; } print "----\n$t\n";
Could someone please enlighten me to my fault and offer a solution for processing piped content and command line args? I've got a feeling I might have to check for command arguments and then if there are none then open up the standard input stream to receive content?

Regards Paul.

In reply to Receiving Standard Input/Piped by thekestrel

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.