in reply to Check for a new line

Instead of printing STATISTICIS directly, collect it in an array. This allows you to react to it.

Replies are listed 'Best First'.
Re^2: Check for a new line
by h123 (Novice) on Jan 27, 2014 at 12:35 UTC
    Hi, At the moment I'm just printing to the screen to test but in my loop I have done something like this:
    $STAT_LINE = "$_"; push (@TOTAL_STATS, $STAT_LINE); if (@TOTAL_STATS >= $SPF) { foreach(@TOTAL_STATS) {print "$_"}; splice @TOTAL_STATS; }

    But when there is no new line to print, the program just keeps waiting for a new line. What I want is a way to say that if there is no new line after 10 seconds push "Error" to the array

      I don't see where this changes, assuming you have the time thing sorted out. If you don't, you could try something like
      my $start_time = time(); my @data; while (time() < $start_time + 10) { # try to populate @data here } if (!@data) { print "error!\n"; } else { print @data; }

      Unless I'm misunderstanding the problem, which is entirely possible.

        Hi,

        The problem I have is that my open() command executes a program on the server(program A) that get stats from another program on the server(program B). When 'B' is running 'A' prints out a line every 10 seconds like this:

        TIMESTAMP - value,value,value,value.

        But if 'B' dies 'A' just hangs waiting for 'B' to come back up and doesn't print a new line until it can get stats from 'B'.

        So my while loop is still running and I want a way to log "Error" if no more new lines are returned every 10 seconds.