D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

RE: [LUG] apache perl cgi question



Title: RE: [LUG] apache perl cgi question

Dave,

Broken Pipe is raised when a process writing to a pipe 'looses' the reader process.  Most likely one of the sort's is writing more data than head wants.  For example, if head wants 10 lines and then finishes, what does sort do with the rest?

It is a good idea to try and avoid multi-stage pipelines run from system() because they are inefficient. Using this method is understandable because this is your first perl program after all!  My suggestion is that you do not use head, but use Perl to capture the data and display it.  Which method you use depends on volumes (I don't know Apache).  For relatively small amounts of data you can read the whole lot into an array with: @array = `ntpdc...`;, then print a slice of the array.  For large amounts of data open a pipe to the process: open(HANDLE, 'ntpdc... |') or die "$!"; then read each line in a loop:  while (<HANDLE>){print $_; ...}  not forgetting to close (HANDLE); when you are finished.

With a bit more work you might be able to do away with the sort as well, although that might not be worth the effort.

Clive




________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Lynx friendly