List::B...rch::PP(3)
π
okay so you've landed on the List::BinarySearch::PP(3) manual page β part of the User Contributed Perl Documentation situation, and the pure-Perl bestie of the binary search world. no cap, it's giving "backup plan that still slays." π
πΈ NAME πΈ
List::BinarySearch::PP β Pure-Perl Binary Search functions. That's literally the whole name vibe. π
π SYNOPSIS π
This module is a plugin for List::BinarySearch, and it's here to give you a graceful fallback to a pure-Perl binary search implementation if the optional (but default) List::BinarySearch::XS dependency can't be built on a target system. It ships as part of the List::BinarySearch distribution. π¦
Examples, bestie β copy these exactly:
use List::BinarySearch qw( binsearch binsearch_pos binsearch_range );
# Find the lowest index of a matching element.
$index = binsearch {$a <=> $b} 300, @{[ 100, 200, 300, 400 ]};
$index = binsearch {$a cmp $b} 'Mozart', @{[ qw/ Bach Brahms Mozart / ]};
$index = binsearch {$a <=> $b} 42, @{[ 10, 20, 30 ]} # not found: undef
# Find the lowest index of a matching element, or best insert point.
$index = binsearch_pos {$a cmp $b} 'Chopin', @{[ qw/ Bach Brahms Mozart/ ]}; # Insert at [2].
$index = binsearch_pos {$a <=> $b} 60, @{[ 10, 20, 30, 40, 50, 70 ]}; # Insert at [5].
$index = binsearch_pos {$a <=> $b} 20, @{[ 10, 20, 30 ]}; # Matched at [1]
β¨ DESCRIPTION β¨
So this module is intended to be used by List::BinarySearch, and it shouldn't need to be used directly in user-code. It's a supporting character, not the main character β unless you're specifically poking at the pure-Perl guts. π
It provides pure-Perl implementations of the binsearch and binsearch_pos functions for use by List::BinarySearch. For a full description of those functions, please refer to the documentation for List::BinarySearch. What follows is a very brief overview. π«Ά
These pure-Perl functions will be overridden by XS code when used via List::BinarySearch if List::BinarySearch::XS is installed β which is the default, and recommended. The pure-Perl functions exist as a graceful downgrade in case users aren't able to use XS modules. π
Bestie, this is a support module. List::BinarySearch is the one driving. π
π§ EXPORT π§
List::BinarySearch::PP exports by default binsearch and binsearch_pos. That's it. Those two. Slay. β¨
π₯ SUBROUTINES/METHODS π₯
π
binsearch CODE NEEDLE ARRAY_HAYSTACK π
$first_found_ix = binsearch { $a cmp $b } $needle, @haystack;
Uses the supplied code block as a comparator to search for $needle within @haystack. If $needle is found, the return value is the lowest index of a matching element. If it isn't found, you get undef. No match, no index, just undef energy. π
π¦ binsearch_pos CODE NEEDLE ARRAY_HAYSTACK π¦
$first_found_ix = binsearch_pos { $a cmp $b } $needle, @haystack;
Uses the supplied code block as a comparator to search for $needle within @haystack. If $needle is found, the return value is the lowest index of a matching element. If it isn't found, you get the index of the best insertion point for the needle. It's giving "you're not here yet, but here's where you should go." π
π οΈ CONFIGURATION AND ENVIRONMENT π οΈ
Perl 5.8 or newer required. That's the requirement, bestie. β
This module is part of the List::BinarySearch distribution, and is intended for use by the List::BinarySearch module. Though the user interface is unlikely to change, it shouldn't be directly used by code outside of this distribution. It's an internal bestie, not a direct-use situation. π«Ά
π DEPENDENCIES π
Perl 5.8. That's the whole dependency list. Iconic. π
π INCOMPATIBILITIES π
Perl versions prior to 5.8 aren't supported by this distribution. See the POD from List::BinarySearch for a more detailed explanation. Do not pass go with pre-5.8 Perl. π
π AUTHOR π
David Oswald, davido at cpan.org. π
If the documentation fails to answer your question, or if you have a comment or suggestion, send me an email. He literally said email him. π«Ά
π DIAGNOSTICS π
No diagnostics listed here, bestie. crickets. π¦
π BUGS AND LIMITATIONS π
Please report any bugs or feature requests to https://github.com/daoswald/List-BinarySearch/issues. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. That's the whole feedback loop, and it's lowkey iconic. π
π SUPPORT π
You can find documentation for this module with the perldoc command:
perldoc List::BinarySearch
This module is maintained in a public repo at Github. You may look for information at:
- Github β development is hosted on Github at
http://www.github.com/daoswald/List-BinarySearch. π¦ - GitHub Issue tracker β report bugs here:
https://github.com/daoswald/List-BinarySearch/issues. π - AnnoCPAN β Annotated CPAN documentation:
http://annocpan.org/dist/List-BinarySearch. π - CPAN Ratings β
http://cpanratings.perl.org/d/List-BinarySearch. β - Search CPAN β
http://search.cpan.org/dist/List-BinarySearch/. π
π§ ACKNOWLEDGEMENTS π§
Shoutout to Mastering Algorithms with Perl at http://shop.oreilly.com/product/9781565923980.do, from O'Reilly at http://www.oreilly.com β much of the code behind the positional search came from there. Respect the source, bestie. πβ¨
π LICENSE AND COPYRIGHT π
Copyright 2013 David Oswald. π
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. Choose your license adventure. π
See http://dev.perl.org/licenses/ for more information. β
Okay bye bestie β List::B...rch::PP(3) is signing off with perl v5.42.2 and a 2026-02-15 timestamp. πβ¨
π¦ where this page comes from
- alpine 3.24: perl-list-binarysearch-doc 0.25-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms