Skip to content

Instantly share code, notes, and snippets.

@charleyramm
Last active November 24, 2015 22:55
Show Gist options
  • Save charleyramm/7f615d95e7c606e5d0fc to your computer and use it in GitHub Desktop.
Save charleyramm/7f615d95e7c606e5d0fc to your computer and use it in GitHub Desktop.
$OUTPUT_AUTOFLUSH = 1; # this thing turns off buffering between newlines
while (1) {
print "perl% ";
my $command = <STDIN>; # get some user input
last if $command eq ''; # exit the loop
chomp $command; # remove newline from our input
my ($program, @args) = split /\s+/, $command;
my $pid = fork;
if (! defined $pid) { print STDERR "Couldn't fork: $!\n" }
elsif ($pid != 0) { wait } # I am the parent
else { exec $program, @args; # I am the child
die "Couldn't exec: $!\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment