Array-Lookup

 view release on metacpan or  search on metacpan

Lookup.pm  view on Meta::CPAN

the C<$key>.

=item $err

A flag indicating if the lookup failed because of no matches at all (''), or
if the lookup failed because of too many matches (C<\@matches>);

=item $msg

A format string used to format and print the error message.  It should
contain two I<printf> substitution sequences: C<%s>.  The first will be
substituted with the failed lookup key; the second with one of the
phrases: C<"not found"> or C<"is ambiguous">, depending upon C<I<$err>>.

If C<I<$msg>> is omitted or null, a default message will be used:

  "lookup failed: %s %s; use one of:\n"

followed by a listing of the strings in the C<I<$keywords>> array.

=back

=head1 EXAMPLES

=head2 Using arrays

    use Array::Lookup;
    ...
    @keywords = qw(quit find get set show);
    ...
    $command = <STDIN>;
    $command = lookup $command, \@keywords, 
	sub { lookup_error @_, "Unknown command '%s'; use one of:\n"; },
	sub { lookup_error @_, "Command '%s' %s; use one of:\n"; };

=head2 Using hashes

    use Array::Lookup;
    ...
    %Commands = ( 'quit' => \&quit,  'get' => \&get,  'set' => \&set,
    	          'find' => \&find,  'show' => \&show );
    ...
    $input = <STDIN>;
    $command_sub = lookup $input, \%Commands, 
	sub { lookup_error @_, "Unknown command '%s'; use one of:\n"; },
	sub { lookup_error @_, "Command '%s' %s; use one of:\n"; };

=head1 SEE ALSO

L<Array::PrintCols>

=head1 AUTHOR

Alan K. Stebbens <aks@stebbens.org>

=cut


# Emacs Local Variables:
# Emacs mode: perl
# Emacs backup-by-copying-when-linked: t
# Emacs End:



( run in 0.676 second using v1.01-cache-2.11-cpan-e1769b4cff6 )