Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Sort hash with values

by Laurent_R (Canon)
on Jun 23, 2013 at 21:49 UTC ( [id://1040344]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Sort hash with values
in thread Sort hash with values

Hi,

I don't know how the OP wants his/her data sorted, but really there is no need for the mySort subroutine. Because, all that that subroutine is doing can be done in a sort block...

Yes, you are right, but I guess that Farang wanted to offer a fix while changing as little as possible from the original code. It is often a dilemma for me (here and on other forums) when I see a clear coding error as well as a number of more or less clumsy or suboptimal things around: should we just give the bug fix to make the program work, toi solve the OP's immediate problem, or should we try to refactor the whole shebang. Sometimes, when I have time, I take the trouble of saying something like this: "your error is there, on this line of code, this is what you need to fix; but, BTW, I would think that it would also be better to (follow the following best practices | use a hash instead of an array (or an array instead of a hash) | work the algorithm the other way around | use the following (cleaner|more robust|faster) syntax | use strict and use warnings | use Perlish loops rather than C-style loops | use tr/// instead of s///g | use index instead of a regex | use map and grep instead of foreach (or foreach instead of map and grep) | whatever | etc.). But I don't always have time and I don't always do it.

Replies are listed 'Best First'.
Re^4: Sort hash with values
by farang (Chaplain) on Jun 24, 2013 at 02:16 UTC

    Yeah, that's basically it. I hadn't looked closely at the mySort function until after I posted, because the sort results seemed reasonable. When I did look, it seemed awkward at best, so I made note of that in an update. I was confident other monks would address it much better than I could on the spur of the moment, and sure enough 2teez and AnomalousMonk have now done just that.

Re^4: Sort hash with values
by Anonymous Monk on Jun 24, 2013 at 01:35 UTC

    But I don't always have time and I don't always do it.

    And more often than not, advice like that is simply ignored -- being lazy is good, doesn't waste your time, doesn't annoy the OP :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1040344]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found