domenica 20 novembre 2016

Movie-like film reader/printer based on Perl 5

Again I found myself inspired by a blogs.perl.org post that demonstrate how to let a computer print stuff as it was reasoning on what it was printing, that is a movie-like message reader. In other words, a king of char-by-char cay(1) implementation. So, how difficult could it be to do it in Perl 5?

As you can imagine it is pretty simple: it does read an input file one char at a time, placing it into the topic variable ($_) and printing it on the screen (using autoflush, of course). Then I wait for a quite random time depending on the fact the char was a letter or something else. In this way I can simulate someone is really writing down the message, stopping after a dot or anew line.

I have to use millisecs sleep in order to make it usable at all, since perl func sleep accepts only integers, and printing a message one second at time is a little dummy!