Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Sorting based on existence of keys
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Uri Guttman, post: 4863071"] JE> There are four different cases you have to consider in your custom JE> compare function: JE> $h{$a} and $h{$b} exist ===> length($h{$a}) <=> length($h{$a}) JE> $h{$a} exists but $h{$b} doesn't ===> -1 JE> $h{$a} does't exist but $h{$b} does ===> 1 JE> Neither $h{$a} nor $h{$b} exists ===> 0 this is why doing a prefilter on the sort keys makes life much simpler. then you only have 1 real case to worry about - whether a key exists or not. you can replace a non-existant key with a fake one that always sorts higher than normal keys. this can be done in an ST or in the key extraction code in Sort::Maker. i leave how to do that as an exercise but it is much simpler than all the double sided checking you propose. uri [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Sorting based on existence of keys
Top