in reply to Calling a subroutine - which is most efficient?
Thanks for your thoughts, folks. It's nice to know that the two methods are equal and I now have some food for thought too.
I actually need to use a mixture of the two methods - sometimes the subroutine will be changing another key in the same hashref, thus the reference will need to be passed as per the first method. Other times the key in my main hashref may point to a different value and thus I don't want it associated at that point - so the second method would apply.
@GrandFather - point taken. Wouldn't want to waste VAT (Valuable Ale Time) for a few ms that nobody will ever notice. I have to confess that I do 'waste' a certain amount of time going back and 'fixing' working code (at my expense, not the client's) - which could be better spent on other things (including beer time). But then this tidying up generally takes the form of simplification and making things more consistent, which does make the code easier to follow when I come back to it later.
@Anonymous Monk - yes, the second method makes the subroutines easier to re-purpose as they aren't always going to be working on the same hashref. I just need to apply the first method when the subroutine actually does stuff to the referenced hash.
@dragonchild - I tend away from OO because my mind tends to work best the other way. (Hey, otherwise I'd be at JavaMonks - just joking ;-)) So, the tendency would be to passing values rather than hashrefs, but there are times when I would be wanting to do stuff to key values in the referenced hash so would duly pass the hashref. I know exactly what's going on in both cases due to my prolific use of comments, so no real issues of maintainability. Nice to know that neither method is 'better' than the other though.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Calling a subroutine - which is most efficient?
by mpeever (Friar) on Oct 26, 2008 at 22:06 UTC |