thekestrel has asked for the wisdom of the Perl Monks concerning the following question:
...I want to be able to go some thing like-->process file1 file2 file3
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.-->ls file* | process
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?#!/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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Receiving Standard Input/Piped
by sk (Curate) on Sep 08, 2005 at 15:42 UTC | |
by thekestrel (Friar) on Sep 08, 2005 at 16:06 UTC | |
by sk (Curate) on Sep 08, 2005 at 16:14 UTC | |
|
Re: Receiving Standard Input/Piped
by Codon (Friar) on Sep 08, 2005 at 17:31 UTC | |
by thekestrel (Friar) on Sep 08, 2005 at 22:16 UTC | |
|
Re: Receiving Standard Input/Piped
by Tanktalus (Canon) on Sep 08, 2005 at 17:01 UTC | |
|
Re: Receiving Standard Input/Piped
by halley (Prior) on Sep 08, 2005 at 16:51 UTC |