Hi Jon, On Tuesday 12 March 2002 11:54 am, Jon Molin wrote: > Gary Stainburn wrote: > > Hi all, > > > > I've got a project where I need to develop an single-board-computer based > > network device using packet modems connected to Amateur Radio equipment > > and I'm trying to develop a simulator in Perl under Linux and I've got a > > few questions. > > > > Basically I'm going to have X number of nodes running inside Xterm > > sessions, all sitting in the same working directory and simulating > > transmitting data by appending the data to a file. Each program will > > simulate receiving the data, by doing the equivelent of a tail -f on this > > file. > > > > Keyboard input will be used to simulate data being received from the > > box's serial port. > > > > 1) How can I simulate the 'tail -f' under perl without hanging my > > program. > > open (F, 'tail -f /var/log/messages |'); > while (<F>) > { > # do stuff > } > close (F); >
This won't do because my code will hang on the file reading part of the while(<F>) statement and prevent any further processing until some data is available. My program will be simultaniously handling incoming data from the radio (this file) and a serial port (the keyboard) while processing real-time data that has already been received. > > If I pseudo code it it may give a better idea of what I mean. > > > > // in main code > > > > if ($command=&getcommand()) { > > &do_something($command); > > } > > > > sub getcommand() { > > if character available > > add character to buffer > > if character = end.of.packet > > return buffer > > else > > return false > > } > > > > 2) can this same method be used to get the characters from the keyboard. > > read 'perldoc perlopentut', go to the part with pipes Pipes are not really required here as I've already got a valid input stream from the Xterm session - STDIN. All I need to do is to be able to check the status of the stream, and if data is available then read it. > > > 3) can I reduce the priority of these programs (equivelent of the unix > > 'nice' command) from within the perl script or do I need to do it from > > the shell script calling the program. (If I nice -> xterm -> perl script, > > will the nice still affect the perl script or will I have to do xterm -> > > nice -> perl script)? > > open (F, 'nice -15 tail -f /var/log/messages |'); Surely, this will only reduce the priority of the nice command and not my perl app? > > > 4) Is there an easy way (or a hard way) within Perl to control the xterm > > output, something similar to GotoXY that I used to have in TurboPascal in > > the good old (?) DOS days. > > i've never used dos (not even in the good old turbopascal days) but > there are term modules: > http://www.cpan.org/modules/by-module/Term/ > i bet they offer alot of control I'll look into these, thanks. > > > /Jon > > > -- > > Gary Stainburn > > > > This email does not contain private or confidential material as it > > may be snooped on by interested government parties for unknown > > and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]