in reply to parsing the results of the subroutine in real time

Knowing what OS would help.

So would answers to such questions as

Please read On asking for help and How do I post a question effectively?.

Nonetheless, here's a WAG -- barebones, unelaborated pseudocode for near-"real time" reading -- avoiding many OS specific ways to check what the executable is up to, the possibility (probability?) that the output is formatted as something other than simple text, whether the executable locks the file it's writing in increments, etc.

#!shebang use strict; use warnings; # do ...; # (whatever sets up the call) call executable # (using system, exec, backticks or ....); # First time check for file written by executable if (exists $thefile) { # the file_in_line_13) { readit(); } else { sleep (some amount of time); goto (in some form or another) 18; } sub readit { open '<', EXEOUT, $thefile ; $latest = <EXEOUT>; close EXEOUT; print "$latest \n"; # (to user); recheck(); } sub recheck { my $timesIdential = 1; sleep (time); open '<', EXEOUT, $thefile ; $newlatest = <EXEOUT>; if ( $newlatest ne $latest ) { clearscreen (OS dependant); readit(); } else { $timesIdentical++; if ($timesIdentical = n) { # for some "n" sufficient to convince you # that the executable is done clearscreen; print "Done\n\n" . $newlatest . "\n"; exit(); } } }

As always, the devil is in the details.

Update, given the detail (parallel processing) in the reply below.

Change line 22 to call a sub wherein (given this structure) you'll throw out any prior processing (wasteful and probably NWYW (® "not what you want") and to do your processing (again).

But we still have no idea of how intensive that processing is, nor how time-critical. Each of those will probably make the replacement suggested in the previous paragraph, in the infamous words of a one-time White House spokesman, "inoperative."

Replies are listed 'Best First'.
Re^2: parsing the results of the subroutine in real time
by doar4forum (Initiate) on Apr 04, 2008 at 21:00 UTC
    Hi, First of all..thank U all for the fast responses:) So...i know that a perl script script is executed line by line...the idea is that i dont want to wait for the entire executable to be finished and then read the outfile...i want as the executable its start running to start reading from the file asweel and process the results in parallel...like writing on the same line : execute && read :D P.S. im working in Linux Thanks!
      I think you have some bad information on how Perl programs run. I also think you have some bad information on how input and output work. You might want to read up a bit on how those things happen, and you might want to share that information with whoever told you those things.

      The first set of Perl code here, for example, autoflushes the output buffer after every print, does a substitution, prints, sleeps for a second, then starts with the next line. The second instance of perl just prints everything it gets from STDIN as soon as it gets it.

      perl -ne '$|++; s/print/say/; print $_; sleep 1;' ffi/test.input | per +l -pe ''

      On Linux you actually have some OS-supported options like Unix sockets, named pipes, and such. You can open a file for writing by one process and for reading by another, and the data goes from the one to the other.

      Perl fully handles reading and writing lines of output in other than batch-style modes, though, as it's a general purpose programming language.

        Hi, Maybe i was not clear so....my apologies... Lets say i have the code lines below: &executable(in,out); &process_executable(out); The script will run first the executable subrotuine and when the process finishes it will execute the process_executable subrotine which takes the output of the executable. What i want its to know how can i simultaneously start the executable subrotuine and not wait for the output but instead read the output as it is written....something like: &executable(in,out) && &process_executable(out);