in reply to Re: perl inline::c sorting problem
in thread perl inline::c sorting problem
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: perl inline::c sorting problem
by BrowserUk (Patriarch) on Apr 30, 2009 at 06:47 UTC | |
by dalittle (Novice) on Apr 30, 2009 at 18:44 UTC | |
by BrowserUk (Patriarch) on May 01, 2009 at 01:52 UTC | |
by dalittle (Novice) on May 01, 2009 at 19:57 UTC | |
by BrowserUk (Patriarch) on May 02, 2009 at 06:38 UTC | |
by tye (Sage) on May 02, 2009 at 04:26 UTC | |
by BrowserUk (Patriarch) on May 02, 2009 at 05:32 UTC | |
|