On 03/19/04 02:30, Bryan Harris wrote:

I have a handy-dandy script that replaces text in files. Very slick:


% replace 'dog' 'cat' myfile.txt
1.  myfile.txt (1 change)

But I'd also like it to be able to act on a pipe if there is one:

% cat myfile.txt | replace 'dog' 'cat'
My cat has fleas.

The problem is I don't want to use the diamond operator if the pipe is empty
because it waits for keyboard input, and I don't want it to.  Is there a way
to check to see if there's anything coming down a pipe?

just put a hyphen on the commandline when you want to read from STDIN (e.g. piped input):


% cat myfile.txt | replace 'dog' 'cat' -

should work without any change to your code.

Randy.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to