18 May 2009 18:54:56 UTC
- Distribution: Algorithm-BestChoice
- Module version: 0.01
- Source (raw)
- Browse (raw)
- How to Contribute
- Clone repository
- Testers (564 / 3 / 0)
- KwaliteeBus factor: 0
- 83.33% Coverage
- License: perl_5
- Activity24 month
- Download (24.66KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionRKRIMEN Robert Krimen
- COPYRIGHT & LICENSE
Algorithm::BestChoice - Choose the best
# 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
<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.
You can find documentation for this module with the perldoc command.
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
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.
Module Install Instructions
To install Algorithm::BestChoice, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Algorithm::BestChoice
For more information on module installation, please visit the detailed CPAN module installation guide.