The best way to avoid this type of 'accident' is to call your subroutines with a pair of parentheses. Yes, you can use the '&' symbol to call your subroutines (ie: &foo;), but IMO it makes things uglier. IIRC, the & symbol is a depreceated method of calling a subroutine. Yes, it's easy to see that you are calling a custom (not a core) subroutine, but it clutters code.

Because everybody here cares so much, here's my favorite (and long-time) way of writing up scripts. Personally, I always put my subroutines at the top, write up a main() sub (like C/C++ which I have never used), and call main() at the bottom. I always use parentheses to call my subs, whether I am passing arguments or not.

#!perl -w use strict; sub main { print "Welcome to my program!\n"; my ($name, $email) = ( get_input('Your Name'), get_input('Your Email Address') ); say_hello($name, $email); } sub get_input { my $msg = shift; print $msg, ': '; chomp( $_ = <STDIN> ); return $_; } sub say_hello { my ($name, $email) = @_; print "Hello $name, I have sent mail to $email!\n"; } main();


In reply to Re: Forward-referenceing subs by Coruscate
in thread Forward-referenceing subs by John M. Dlugosz

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.