How to read piped input in Perl?
        Posted  
        
            by Jenni
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jenni
        
        
        
        Published on 2010-03-19T19:30:08Z
        Indexed on 
            2010/03/19
            19:31 UTC
        
        
        Read the original article
        Hit count: 266
        
I am trying to create something in Perl that is basically like the Unix "tee" command. I'm trying to read each line of STDIN, run a substitution on it, and print it. (And eventually, also print it to a file.)  This works if I'm using console input, but if I try to pipe input to the command it doesn't do anything.  Here's a simple example:
print "about to loop\n";
while(<STDIN>)
{
  s/2010/2009/;
  print;
}
print "done!\n";
I try to pipe the dir command to it like this:
C:\perltest>dir | mytee.pl about to loop done!
Why is it not seeing the piped input?
© Stack Overflow or respective owner