↓Skip to main content
  1. /classes/
  2. Classes, Fall 2026/
  3. CS 2010 Fall 2026: Course Site/

cs2010 Notes: 10-28 More Programing

·76 words·1 min·

We’re going to build a spellcheck program.

We’re going to do it in Perl.

#!/usr/bin/perl
use 5.30.0;

open my $wf, "<", "/usr/share/dict/words";
my %words = ();
while (<$wf>) {
  chomp;
  $words{$_} = 1;
}
close $wf;

while (<>) {
  chomp;
  s/[^\w\s]//g;
  y/[A-Z]/[a-z]/;
  my @words = split /\s+/;
  for my $word (@words) {
    say $word unless $words{$word};
  }
}

We’re going to walk through that step by step.

If we have time, we’ll rewrite it in C.

Nat Tuck
Author
Nat Tuck