Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
XP is just a number
 
PerlMonks  

a reading/presentation prog

by stabu (Scribe)
on Jul 21, 2005 at 07:04 UTC ( [id://476774]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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:

  • slurp the file lines as a scalar
  • split according to sentences
  • put into an array and then
  • print the array elements out,
  • waiting a certain time interval each time.

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 07:21 UTC
    while ( <> ) { print; sleep(60); }


    holli, /regexed monk/
Re: a reading/presentation prog
by anonymized user 468275 (Curate) on Jul 21, 2005 at 07: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 14: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://476774]
Approved by Nevtlathiel
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.