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.Perl_sortsv_flags(aTHX_ AvARRAY(data),arrayLen+1,Perl_sv_cmp, flags);
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.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);
In reply to Re^2: perl inline::c sorting problem
by syphilis
in thread perl inline::c sorting problem
by dalittle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |