NAME
Data::Cmp::StrOrNumeric - Compare two data structures, return -1/0/1 like cmp or <=>
VERSION
This document describes version 0.010 of Data::Cmp::StrOrNumeric (from Perl distribution Data-Cmp), released on 2021-04-12.
SYNOPSIS
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
}
DESCRIPTION
VARIABLES
$EPSILON
Can be set to perform numeric comparison with some tolerance. See example in Synopsis.
FUNCTIONS
cmp_data
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.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Data-Cmp.
SOURCE
Source repository is at https://github.com/perlancar/perl-Data-Cmp.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/perlancar/perl-Data-Cmp/issues
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.
SEE ALSO
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021, 2019, 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.