1#!./perl 2 3print "1..4\n"; 4 5$DICT = <<EOT; 6Aarhus 7Aaron 8Ababa 9aback 10abaft 11abandon 12abandoned 13abandoning 14abandonment 15abandons 16abase 17abased 18abasement 19abasements 20abases 21abash 22abashed 23abashes 24abashing 25abasing 26abate 27abated 28abatement 29abatements 30abater 31abates 32abating 33Abba 34EOT 35 36use Search::Dict; 37 38open(DICT, "+>dict-$$") or die "Can't create dict-$$: $!"; 39binmode DICT; # To make length expected one. 40print DICT $DICT; 41 42my $pos = look *DICT, "Ababa"; 43chomp($word = <DICT>); 44print "not " if $pos < 0 || $word ne "Ababa"; 45print "ok 1\n"; 46 47if (ord('a') > ord('A') ) { # ASCII 48 49 $pos = look *DICT, "foo"; 50 chomp($word = <DICT>); 51 52 print "not " if $pos != length($DICT); # will search to end of file 53 print "ok 2\n"; 54 55 my $pos = look *DICT, "abash"; 56 chomp($word = <DICT>); 57 print "not " if $pos < 0 || $word ne "abash"; 58 print "ok 3\n"; 59 60} 61else { # EBCDIC systems e.g. os390 62 63 $pos = look *DICT, "FOO"; 64 chomp($word = <DICT>); 65 66 print "not " if $pos != length($DICT); # will search to end of file 67 print "ok 2\n"; 68 69 my $pos = look *DICT, "Abba"; 70 chomp($word = <DICT>); 71 print "not " if $pos < 0 || $word ne "Abba"; 72 print "ok 3\n"; 73} 74 75$pos = look *DICT, "aarhus", 1, 1; 76chomp($word = <DICT>); 77 78print "not " if $pos < 0 || $word ne "Aarhus"; 79print "ok 4\n"; 80 81close DICT or die "cannot close"; 82unlink "dict-$$"; 83