Algorithm::BestChoice - Choose the best
Version 0.01
# Find my favorite food based on color my $chooser = Algorithm::BestChoice->new; $chooser->add( match => red, value => cherry, rank => 1 ) $chooser->add( match => red, value => apple, rank => 10 ) # Like apples $chooser->add( match => red, value => strawberry, rank => -5 ) # Don't like strawberries $chooser->add( match => purple, value => grape, rank => 20 ) # Delicious $chooser->add( match => yellow, value => banana ) $chooser->add( match => yellow, value => lemon rank => -5 ) # Too sour my $favorite; $favorite = $chooser->best( red ) # apple is the favorite red $favorite = $chooser->best( [ red, yellow, purple ] ) # grape is the favorite among red, yellow, and purple
An Algorithm::BestChoice object is similar to a hash, except it returns a result based on a given key AND relative ranking. That is, you can associate multiple values with a single key, and differentiate them by using a rank (or weight).
Create and return a new Algorithm::BestChoice object
Add a possible choice to the chooser
The arguments are:
match The key for the choice, can be a string or a regular expression value The value to associate with the key (what is returned by ->best) rank An optional numeric weight, the default is 0 (>0 is better, <0 is worse)
Given criterion, ->best will return the value that 1. has a matching matcher and 2. has the highest rank
Robert Krimen, <rkrimen at cpan.org>
<rkrimen at cpan.org>
Please report any bugs or feature requests to bug-algorithm-bestchoice at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Algorithm-BestChoice. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-algorithm-bestchoice at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Algorithm::BestChoice
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Algorithm-BestChoice
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Algorithm-BestChoice
CPAN Ratings
http://cpanratings.perl.org/d/Algorithm-BestChoice
Search CPAN
http://search.cpan.org/dist/Algorithm-BestChoice/
Copyright 2009 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Algorithm::BestChoice, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::BestChoice
CPAN shell
perl -MCPAN -e shell install Algorithm::BestChoice
For more information on module installation, please visit the detailed CPAN module installation guide.