Actually you can call a sub like so: sub_name()

Behold the difference in the output of the following snippet

print "Now testing with the ampersand\n"; &ampersand('arg1', 'arg2'); print "Now testing with the ampersand, but with 'blank' arguments\n"; &ampersand_blank_arg; print "Now testing without the ampersand\n"; no_ampersand('arg1', 'arg2'); sub ampersand { &two; } sub ampersand_blank_arg { &two(); } sub no_ampersand { two(); } sub two { print "@_\n"; } __OUTPUT___ Now testing with the ampersand arg1 arg2 Now testing with the ampersand, but with 'blank' arguments Now testing without the ampersand

The side effect obviously visible with using the ampersand is that it passes the @_ from the sub that called it. And of course, this could easily be thwarted by just putting the empty parens behind the sub name (as demonstrated by ampersand_blank_arg). But I also read on this site ((tye)Re: A question of style) that using the ampersand screws with prototypes.

In the beginning, I used them all the time. Then I pulled my hair out for about a week because I accidentally happened upon the @_ problem. I then started to put the empty parens behind them. But I'm human. I forgot sometimes and I'd kick my self everytime I found one that I missed. Then I found out that you don't need the ampersand if you use the parens and if you forget the parens, you get a bareword error. I love it when Perl tells me I've screwed up.


In reply to Re^3: Sub Return Value Help by BurnOut
in thread Sub Return Value Help by Anonymous Monk

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.