I'm attempting to use case folding, when available, as the "more correct" version of case-insensitive string comparisons. However, it's only available for versions of Perl from v5.16 onwards, and I'd like to maintain backward compatibility (back to v5.8.8). So, I have a small section of version dependent code. My current solution uses stringy eval to protect it from compilation error in earlier Perl versions:
use strict;
use warnings;
use utf8;
use 5.008008; # minimum perl version ## v5.8.8 ~ required for decent
+ basic Unicode support
my @list = qw/ Foo bAR baZ /;
if ( $] ge '5.016' ) {
## no critic ( ProhibitStringyEval RequireCheckingReturnValueOfEva
+l )
eval q/@list = sort { ( CORE::fc $a ) cmp ( CORE::fc $b ) } @list;
+/
}
else { @list = sort { ( lc $a ) cmp ( lc $b ) } @list; }
print qq/[ @list ]/,"\n";
It works but seems a bit crufty to me. I'd love to hear opinions or about any alternative formulations.
Thanks.