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.


In reply to Re: Calling a subroutine - which is most efficient? by smiffy
in thread Calling a subroutine - which is most efficient? by smiffy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.