Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am running a software packege built on Baeysian statistics concept. at regular intervals i got to run some analysis(while Mr.Bayes is still running) and copy such results to another location. Is there any way set this in perl? I use wc -l <some program> to fix intervals that I want ot run. Please help me, Thanks in advance,

Replies are listed 'Best First'.
Re: sampling with perl script
by Illuminatus (Curate) on Oct 16, 2008 at 18:24 UTC
    Please read How do I post a question effectively? It sounds like you have the following:
    1. You have a 'Bayes' program running, writing output to a file
    2. After every N lines of output, you want to perform some processing
    3. This processing is to be done via a perl program
    Is this right? If so, the easiest thing to do would be something like
    open BAYES, "tail -f bayes.out |" || die "could not open: $!"; while (<BAYES>) { # read until you have enough to process }
    If this is not right, you will need to provide a better explanation...

      Of course open BAYES, "tail -f bayes.out |" or die "could not open: $!"; would work even better as it lacks the subtle precedence problem that makes the error checking get optimized away . . .

      (Or one could be fashionable and go for a 3-argument, lexical filehandle form open my $bayes, "-|", qw( tail -f bayes.out ) or die "Couldn't open pipe: $!"; if you're into that kind of thing and have a recent enough perl.)

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.