Data::Cmp::StrOrNumeric - Compare two data structures, return -1/0/1 like cmp or <=>
This document describes version 0.006 of Data::Cmp::StrOrNumeric (from Perl distribution Data-Cmp), released on 2018-12-06.
use Data::Cmp::StrOrNumeric qw(cmp_data); cmp_data(["a", "b", "c"], ["a", "b", "d"]); # => -1 cmp_data([0, 1, 10], [0, 1, 9]); # => 1
Contrasted with Data::Cmp:
use Data::Cmp (); Data::Cmp::cmp_data(["a", "b", "c"], ["a", "b", "d"]); # => -1 Data::Cmp::cmp_data([0, 1, 10], [0, 1, 9]); # => -1
Perform numeric comparison with some tolerance:
{ local $Data::Cmp::StrOrNumeric::EPSILON = 1e-3; cmp_data(1, 1.1 ); # -1 cmp_data(1, 1.0001); # 0 cmp_data([1], [1.0001]); # 0 }
Can be set to perform numeric comparison with some tolerance. See example in Synopsis.
Usage:
cmp_data($d1, $d2) => -1/0/1/2
This module's cmp_data() is just like Data::Cmp's except that when the two non-references being compared look like number (tested using Scalar::Util's looks_like_number(), they are compared with <=> instead of cmp. If none or only one of the non-reference is a number, cmp is used like in Data::Cmp.
cmp_data()
looks_like_number()
<=>
cmp
Please visit the project's homepage at https://metacpan.org/release/Data-Cmp.
Source repository is at https://github.com/perlancar/perl-Data-Cmp.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Cmp
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Data::Cmp
Data::Cmp::Numeric
perlancar <perlancar@cpan.org>
This software is copyright (c) 2018 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Cmp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Cmp
CPAN shell
perl -MCPAN -e shell install Data::Cmp
For more information on module installation, please visit the detailed CPAN module installation guide.