Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'll call the above program "grep". The program works fine for either of these 2 methods :#!/bin/perl -w $names++, shift if $ARGV[0] eq "-l"; $search = shift; $showname = @ARGV > 1; @ARGV = "-" unless @ARGV; @ARGV = grep { -T or $_ eq "-" } @ARGV; exit 0 unless @ARGV; while (<>) { next unless /$search/o; if ($names) { print "$ARGV\n"; close ARGV; } else { print "$ARGV: " if $showname; print; } }
But when I run "grep" by itself, it waits for STDIN. I want the program to print out a "usage message" if the user just runs "grep". How would I do this ?1. grep pattern /tmp/file 2. cat /tmp/file | grep pattern
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Test for standard input
by zigdon (Deacon) on Oct 03, 2002 at 16:36 UTC | |
by goldclaw (Scribe) on Oct 03, 2002 at 17:07 UTC | |
by rowswell (Initiate) on Oct 03, 2002 at 17:22 UTC | |
by sauoq (Abbot) on Oct 03, 2002 at 18:36 UTC | |
by mikfire (Deacon) on Oct 03, 2002 at 18:05 UTC | |
by BUU (Prior) on Oct 03, 2002 at 23:57 UTC | |
|