Skip to content

Instantly share code, notes, and snippets.

@davorg
Last active March 5, 2019 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davorg/20390917e215611a7b5283d5bf4666b3 to your computer and use it in GitHub Desktop.
Save davorg/20390917e215611a7b5283d5bf4666b3 to your computer and use it in GitHub Desktop.
Simple CGI program to answer question on Reddit
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(param header);
my $title = 'Blood Test';
my $content = param('bloodtype') ? get_results() : get_form();
print header;
print <<"EOF_HTML";
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
$content
</body>
</html>
EOF_HTML
sub get_form {
return <<"EOF_HTML";
<form>
<p>What is your blood type?<br><input name="bloodtype" size="5">
<input type="submit" value="Submit"></p>
</form>
EOF_HTML
}
sub get_results {
my %types = (
A => 'Stay away from Amoeba',
B => 'Do not touch any bacteria',
O => 'You need more organic fruit',
AB => 'Try eating more vitamin A and B',
);
my $text = $types{param('bloodtype')} || 'Are you a human?';
return "<p>$text</p>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment