<% use CGI; use PerlEx::Example::spell; my $cgi = new CGI; %> Welcome to PerlEx

PerlEx Examples

Spell Checker

This script checks the spelling of a word against a dictionary of over 45000 words.

How can this be done so quickly in a Perl CGI program? By reading in the dictionary in a BEGIN block and taking advantage of persistent variables, the word list is made to persist in memory between invocations of the program.

Enter a word to spell check:
<% my $word = $cgi->param('word'); if ($word) { $text = spell::check($word) ? "$word is spelled correctly.":"$word is spelled incorrectly"; print $text; } %>

Embedded Perl

Embedded Perl is very similar to ASP, however it will work on any web server that PerlEx supports. Perl code contained in an Embed file is virtually "transparent" to your HTML editor, so you can edit the HTML in the file with relative ease and immediately see what the page will look like in a browser. Embedded Perl code is contained inside ASP style tags (<% perl code %>). Text outside these tags is treated similarly to HEREDOC style printing in Perl. For more information on using Embedded PerlEx, see the PerlEx Documentation.

The following example of Embedded Perl shows the Spell Check example from above.

<html>
<head>
	<title>Welcome to Embedded PerlEx</title>
</head>
<body>

<%
use CGI;
use spell;
my $cgi = new CGI;
%>
<form action="examples.aspl">
Enter a word to spell check:<br>
<input type="text" name="word">
<input type="submit" name="Check"> <%
my $word = $cgi->param('word');
if ($word) {
	$text = spell::check($word) ? 
		"$word is spelled correctly." :
		"$word is spelled incorrectly";
	print $text;
}
%>

</form>
</body>
</html>