[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Search::Dict?



I thought that this would be fairly easy, but it's not and I'd appreciate some
guidance about doing something that should be pretty simple (I think!). All I'm
trying to do is search thru a text file that is literally a dictionary and
extract the entry and definition of a word or phrase if it's in there. The file
is kind of bizarre, but I've got the entry and definition delimited with a tab
and it's obviously already sorted in the correct order.

In playing with DB_File, I found that I could get an arbitrary line by number
just fine, but the question was how to figure out what line number I wanted to
begin with? Then I blundered across Search::Dict and figured that I could use it
to find the entry, get the line number, and use DB_File to actually retrieve the
contents of the line. Unfortunately, it isn't seeing $key and is always
returning line 701 which is the last line in this particular file.

Thus, I am stuck and have pasted the script below. Thanks for any help.

# Use or Require statements:
use Search::Dict;
use DB_File;
use Fcntl;    
######
# Declare variables:
$dict = 1;
$fold = 0;
$key = "Rachel";
$file = "Poindexter:www.sbl-site.org:home:sbl-home:EPubs:d:a.html";
######
# Begin program:
open(F, "<$file");
if (look <F>, $key, $dict, $fold)  {
$line_number = $.;
close(F);
$tie = tie(@lines, "DB_File", $file, O_RDWR, 0666, $DB_RECNO)
    or die "$!\n";
unless ($line_number < $tie->length)    {
    $thelength = $tie->length;
    die "Didn't find line $line_number in the file\n
        File length is $thelength\n"
}
print $lines[$line_number-1];
} else  {
print "Shit\n";
}
untie($file);

Richard Gordon
Gordon Consulting & Design
Voice: 770-565-8267  Fax: 770-971-6887



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch