CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: General Discussions: General Questions:
How to pipe input to a Perl script

 



sandralynn
New User


Feb 5, 2017, 10:42 PM

Post #1 of 2 (1437 views)
How to pipe input to a Perl script Can't Post

Let's say you want to pipe some input to a Perl Script. First, you create this Perl script (pipe_me.pl):


Code
while (<>)  
{
print $_;
}


Then you call the script like this:


Code
 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:


Code
foreach $line (<>)  
{
print $line;
}

Source: Snippets


(This post was edited by sandralynn on Feb 5, 2017, 10:51 PM)


Laurent_R
Veteran / Moderator

Feb 6, 2017, 2:11 PM

Post #2 of 2 (1420 views)
Re: [sandralynn] How to pipe input to a Perl script [In reply to] Can't Post


In Reply To
You can also read the input line by line like this:


Code
foreach $line (<>)  
{
print $line;
}

Source: Snippets


I doubt that this second example is really a good idea. Using a while loop is probably much better.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives