Number::Compare(3)

πŸ¦‹ Number::Compare(3) β€” from the User Contributed Perl Documentation πŸ¦‹

🌸 NAME 🌸

Number::Compare β€” numeric comparisons πŸ’–

✨ SYNOPSIS ✨

Number::Compare->new(">1Ki")->test(1025); # is 1025 > 1024

my $c = Number::Compare->new(">1M");
$c->(1_200_000);                          # slightly terser invocation

πŸ’« DESCRIPTION πŸ’«

Okay so Number::Compare compiles a simple comparison to an anonymous subroutine, and then you can call that subroutine with a value to be tested again. Bestie, that’s the whole vibe check. 🫢

Now this would be very pointless if Number::Compare didn’t understand magnitudes β€” but it absolutely does, no cap. ✨

The target value may use magnitudes of kilobytes (k, ki), megabytes (m, mi), or gigabytes (g, gi). Those suffixed with an i use the appropriate 2**n version in accordance with the IEC standard: http://physics.nist.gov/cuu/Units/binary.html πŸ’…

πŸ› οΈ METHODS πŸ› οΈ

->new( $test )

Returns a new object that compares the specified test. Iconic constructor behavior, honestly. πŸŽ€

->test( $value )

A longhanded version of $compare->( $value ). Predates blessed subroutine reference implementation. Lowkey a little historical, highkey still useful. πŸ¦‹

->parse_to_perl( $test )

Returns a perl code fragment equivalent to the test. It’s giving β€œshow me the receipts, but in Perl.” 🧚

πŸ‘‘ AUTHOR πŸ‘‘

The human behind this masterpiece: Richard Clamp <richardc@unixbeard.net> ✨

Copyright (C) 2002,2011 Richard Clamp.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

πŸ”— SEE ALSO πŸ”—

http://physics.nist.gov/cuu/Units/binary.html β€” go read, bestie, it’s the binary-prefix lore. 🌈


πŸ’Œ source/version perl v5.42.0, dated 2022-04-21, for Number::Compare(3) β€” mwah, go compare some numbers πŸ’‹

πŸ“¦ where this page comes from