On Wed, Jul 8, 2009 at 5:33 PM, Steve Tolkin<[email protected]> wrote:
> I want to do a binary search on a list of strings in memory.  Basically I
> want the bsearch functionality, also implemented in Search::Dict.
> Unfortunately that is documented to only work for a list of strings in a
> file.    http://search.cpan.org/~nwclark/perl-5.8.9/lib/Search/Dict.pm says
> in part: <q>
>
> NAME
>
> Search::Dict, look - search for key in dictionary file
>
>
>
> SYNOPSIS
>
>    use Search::Dict;
>
>    look *FILEHANDLE, $key, $dict, $fold;
>
>
>
>    use Search::Dict;
>
>    look *FILEHANDLE, $params;
>
>
>
> DESCRIPTION
>
> Sets file position in FILEHANDLE to be first line greater than or equal
> (stringwise) to $key. Returns the new file position, or -1 if an error
> occurs.</q>
>
>
>
> Is there any way to have a FILEHANDLE point to an array in memory?
>
> If so, is anything special needed to use the above module?
[...]

  open(my $fh, "<", \$scalar)

will open a filehandle $fh to a "file" which is whatever is in
$scalar.  Pure Perl code, such as Search::Dict, should treat this as a
regular filehandle.

Cheers,
Ben

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to