PERLReadEvalPrint
A simple read-eval-print sort loop in PERL.
#!/usr/bin/perl -w
use strict;
my @scripts = qw/reverse amplify stretch permute/;
sub pick {
# return a random element from an array
return $_[int(rand(@_))];
}
while (1) {
system("clear");
print "*****\n";
print "welcome\n";
print "*****\n";
print "press a key to continue:\n";
system("mplayer /usr/share/sounds/KDE_Beep_Yo.wav > /dev/null 2> /dev/null");
my $line = <STDIN>;
# PICK RANDOM SCRIPT
my $script = pick(@scripts);
# READ LINES FROM KEYBOARD
system("clear");
print "*****\n";
print "Running $script\n";
print "*****\n";
print "type some input, and end with Ctrl-D\n";
print "\n";
system("mplayer /usr/share/sounds/KDE_Keyboard_Key_1.ogg > /dev/null 2> /dev/null");
my @lines = ();
while (1) {
$line = <STDIN>;
if ($line eq "\n") { last };
push(@lines, $line);
}
# RUN SCRIPT AND FEED LINES TO THE SCRIPT (goes to STDIN of script)
my $writeme;
open $writeme, "|-", "./$script";
foreach (@lines) {
print $writeme $_;
}
close($writeme);
system("mplayer /usr/share/sounds/KDE_Pop.ogg > /dev/null 2> /dev/null");
print "\n";
print "DONE\n";
sleep(5);
}