convenientstore
Is there a hard rule regarding when to use subroutine?

No. There hasn't been one and there won't be one anytime soon.

How does one know if using subroutine is better than not using it?

This depends entirely of the absolute knowledge of the person in question. There are aspects of efficiency, comprehensibility, maintainability etc. A subroutine is just one of the means used to transfer a concept into a technical thing, a code or program.

Can you guys share(or at least point me to right direction or URL) your rules or where you learned when the best time to use subroutine?

I learned to use subroutines just naturally, by *not* using them in the beginning. If your knowledge evolves over time, your conceptual view of the optimal structuring and transferability into code starts to include "subroutines", "records" (structured data), "modules" and all these things. Don't try to imitate things which you didn't really internalize. Just don't use any subroutine in your own code until it gets crystal clear for you to do so for a reason you like ...

Regards

mwa


In reply to Re: when to use subroutine by mwah
in thread when to use subroutine by convenientstore

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.