in reply to A proper name for is_sorted function that can check more than just sorting order?

There is a "stupid-simple" way to write this as a sub which returns True or False. Something like:
$a = <file>; while ($b = <file>) { if (($a cmp $b) > 0) return false; $a = $b; } return true;
There. Anyone can understand that in about ten seconds, and debug it and patch it forever. Go ahead and write as many "redundant" functions like this as you care to, because the day might will come when one of them has to be just a little different ... and you prepared for that, so what could be a big change in "clever" code is a small one instead, just as it should be. Your successors will thank you.
  • Comment on Re: A proper name for is_sorted function that can check more than just sorting order?
  • Download Code

Replies are listed 'Best First'.
Re^2: A proper name for is_sorted function that can check more than just sorting order?
by LanX (Saint) on Dec 28, 2017 at 08:09 UTC
Re^2: A proper name for is_sorted function that can check more than just sorting order?
by Dallaylaen (Chaplain) on Dec 28, 2017 at 09:18 UTC

    Generally I prefer to use simple constructs, especially in tests. However, sometimes a well-defined wrapper is better. Something like Test::Warn:

    warnings_like { my_fucntion() } [ {carped => qr/deprecated.*our_function/} ], "Warning issued, alter +native suggested";

    This can be written with $SIG{__WARN__} and like, but why bother? The intention is clear from this code.

    My proposed "test that condition holds for all adjacent values in an array" looks pretty well-defined to me. And if it's insufficient, there's always subtest and a for loop...