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

Re: [MacPerl] Search::Dict?



At 08.55 -0500 1999.02.12, Richard Gordon wrote:
>0 instead of 701, so I guess we're making "progress?" Perhaps I'm just not
>thinking about this whole thing correctly- given that all I want to do is
>extract a given line of text from a file based on a key and print the key and
>the value, would I be better off just using a normal hash? I guess what I am

If that is all you want, it is simple.  Keep in mind that Search::Dict
_must_ have the input file sorted in order to work.  Given a sorted file
like:

abba 1
book 2
car 3
dog 4
edgar 5
freaky 6
george 7
rachel 8
yabba 9
zippo 10


All you need to do is:

#!perl -w
use Search::Dict;

open(IN, "file") or die $!;
look(*IN, 'Rachel', 1, 1);
chomp(my $line = <IN>);
my($k, $v) = split / +/, $line;

print "$k => $v\n";

__END__

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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