You'll probably have to change Perl_sv_cmp_locale to whatever the constant is for <=> though I'm sorry I can't seem to track that down at the moment
I can't find it either. Is there such a thing ? Or is sortsv() invariably lexical ?
I tried
Perl_sortsv_flags(aTHX_ AvARRAY(data),arrayLen+1,Perl_sv_cmp, flags);
for differing values of 'flags', but it looked like 0 (and any even value) causes a lexical sort in ascending order, and 1 (and any odd value) causes a lexical sort in descending order. I didn't stumble across any value that forces a numeric sort.
The following produces the desired output:
use warnings;
use Inline C => Config =>
CLEAN_AFTER_BUILD => 0,
BUILD_NOISY => 1;
use Inline C => <<'END_OF_C_CODE';
void test(AV* data) {
I32 i;
I32 arrayLen;
float retval;
SV** pvalue;
arrayLen = av_len(data);
sortsv(AvARRAY(data),arrayLen+1,Perl_sv_cmp);
for (i = 0; i < arrayLen+1; i++) {
pvalue = av_fetch(data,i,0);
printf("%s \n",SvPVX(*pvalue));
}
}
END_OF_C_CODE
my $ref = [ 5.0e-5,4.2e-5,4.3e-5,4.4e-5,4.4e-5,4.2e-5,4.2e-5,4.0e-5];
for(@$ref) {$_ = sprintf "%f", $_}
test($ref);
I don't know if that's helpful in the "real world" application. All it does is stringify the values in the array reference into such a form that the lexical sort produces the desired output. There may be a better way of achieving that stringification.
Cheers, Rob
|