Register now and start sharing your code snippets.
-->
How to pipe input to a Perl script
Perl posted about 1 year ago by christian
Let’s say you want to pipe some input to a Perl script. First, you create this Perl script (pipe_me.pl):
1 while (<>) 2 { 3 print $_; 4 }
Then you call the script like this:
1 less access.log | perl pipe_me.pl
The script outputs the contents of access.log. To do some real work extend it with your own code—you might want to, for example, analyze an Apache access log.
You can also read the input line by line like this:
1 foreach $line (<>) 2 { 3 print $line; 4 }