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="xhoster, post: 4863068"] You could turn off the uninitialized warning for that block. If you don't want to turn off the warning, you could detect when both are nonexistent and short circuit on that. And since we already know their existence status is equal (otherwise we would have short-circuited on the previous op), then we really only need to detect if one of them is nonexistent. for (sort { exists $h{$b} cmp exists $h{$a} || exists $h{$b} && It seems to do what ought to be done, so in my book that makes it the right tool for the job. I really doubt that future versions of Perl5 is going to change the representations of true and false in a way that the outcome of cmp is going to be different than it currently is. You could also use <=> to get the same outcome, because the special true value is greater than the special false value both stringly ('' lt '1') and numerically (0 < 1) Xho -- -------------------- [URL]http://NewsReader.Com/[/URL] -------------------- The costs of publication of this article were defrayed in part by the payment of page charges. This article must therefore be hereby marked advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate this fact. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Sorting based on existence of keys
Top