Subject: | wishlist: is_uniq, assert_uniq |
Thanks for adding minmaxstr. Could I log another feature request?
The uniq() function is handy but I often find myself using it as
if (scalar(uniq(@a)) != scalar(@a)) {
die "duplicates found in: @a";
}
This is usually for 'cannot happen' cases in the code, where I am sure that @a will have unique values, but I add a check out of paranoia and to document my assumption. Using uniq for this is a lot more concise than building a %seen hash.
However, it could be made more concise (and faster) if you could just test whether a list has only unique elements:
die 'duplicates' unless is_uniq(@a);
Finally, for the kind of assertion above it would be even nicer to have the library routine do the checking and throw an error itself:
assert_uniq(@a);
# 'values not unique: value XXX appears more than once'