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

I want to build a prog to read and concurrently edit edit text files in perl. For the first stage, I just wanted to write up a script which will make the lines of a text file appear one after the other after a certain time interval. I reckon this is achieveable for my elementary perl knowledge.

I plan to:

Sounds like something some one has done already? Is there a wait function in perl? Can I write over the the previously printed-out array elements?

Thanks in adv for advice.

Replies are listed 'Best First'.
Re: a reading/presentation prog
by holli (Abbot) on Jul 21, 2005 at 11:21 UTC
    while ( <> ) { print; sleep(60); }


    holli, /regexed monk/
Re: a reading/presentation prog
by anonymized user 468275 (Curate) on Jul 21, 2005 at 11:43 UTC
    That is assuming sentences are defined by "\n". The input line separator can however be changed early in the program, e.g.:
    $/ = '.'; $snoozeTime = 10; while( <> ) { print $_; sleep $snoozeTime; }
    But if ':' is also needed as a sentence terminator, there are a number of solutions for extracting the ':'-terminated sentences from each '.' separated chunk, especially regular expressions and the built-in function split.

    One world, one people

Re: a reading/presentation prog
by ysth (Canon) on Jul 21, 2005 at 18:10 UTC
    Can I write over the the previously printed-out array elements?
    The easiest way is to turn off buffering and start each output with a carriage return character and end with sufficient trailing blanks:
    $|=1; # flush output after each print @outputs = qw/fred jim sheila barney/; $maxlen = 6; $delaysecs = 1; for my $out (@outputs) { printf "\r%-${maxlen}s", $out; sleep($delaysecs); } print "\n";
    If your sentences wrap onto the next line on the terminal, you'll have to do something more fancy.