Last active
March 5, 2019 08:28
-
-
Save davorg/20390917e215611a7b5283d5bf4666b3 to your computer and use it in GitHub Desktop.
Simple CGI program to answer question on Reddit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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