Also, is there a reason you don't use return in sub get_name? I know you don't have to, but it makes it _much_ easier to detect bugs if you insert new lines at the end of the sub (or, someone else who isn't paying enough attention to your code does.) I'd generally consider always saying 'return' when you want to return a value as one of those habits of highly successful perl programmers.

This is by large a matter of personal taste/preference. I'm not striving for "extreme" conciseness, as that would be "golf" and doesn't make for clarity, but the "Right(TM)" degree of conciseness, which includes avoiding redundant or unnecessary syntax, does make for it. In particular the last line of a sub is already visually distinct enough and I generally consider never saying return unless I want to explicitly return prematurely.

It's not exactly the same thing but the advice of always returning reminds me of the cargo-culted habit of always including an unnecessary

exit 0;

line at the end of one's scripts.


In reply to Re^2: Can i make this more efficient with a special variable? by blazar
in thread Can i make this more efficient with a special variable? by nmerriweather

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.