August 2005
Beginner
464 pages
12h 36m
English
Use Perl CGI scripts to create a prompter that makes it easy to read from a script.
A prompter is a program that puts up the text of a script in large type and scrolls it on a timer. This makes it easy to concentrate on reading the script, instead of scrolling through pages of small type. In this hack I’ll explain how to create a prompter that makes it easy to read from a script.
Save this code as prompter.pl:
#!/usr/bin/perl
use FileHandle;
use CGI;
use strict;
my $q = new CGI();
my $text = $q->param( "text" );
print "Content-type: text/html\n\n";
if ( $text )
{
my $template = "";
my $fh = new FileHandle( "prompter.html" );
while( <$fh> ) { $template .= $_; }
$fh->close();
my @textitems = split /[\n+]/, $text;
my $jsarray = join( ",", map { s/\n|\r//g; "\"$_\"" } @textitems );
$template =~ s/\%\%lines\%\%/$jsarray/;
print $template;
}
else
{
my $fh = new FileHandle( "prompter_form.html" );
while( <$fh> ) { print; }
$fh->close();
}Save this code as prompter.html:
<html>
<head><title>Podcast Prompter</title>
<script language="Javascript">
var lines = [
%%lines%%
];
</script>
<script language="JavaScript">
var wordDelay = 300; // The average time per word in milliseconds function getwordcount( str ) { words = str.split( /\s+/ ); return words.length; } var currentPrompt = 0; var timeoutId = 0; function prompt( index ) { if ( index >= lines.length ) index = lines.length - 1; currentPrompt = index; if ( index > 0 ) line0.innerHTML = lines[ index ...Read now
Unlock full access