I've seen warnings in the docs/on PM/in books about how to call functions, and it finally bit me in a weird way.

Oddly, I recall someone saying that user-defined functions SHOULDN'T be called using & (and if you do use it, to make sure you use parentheses).

That sounded good to me, so I was avoiding using & and (), when I ran into this sort of scenario (in my unit test file):
use Test::More 'no_plan'; require 'some_file_with_my_functions.pm'; my $foo = "hi"; my $bar = " hi"; ok( ThatPackage::blah $foo, 'blah' ); ok( ThatPackage::blah $bar, 'blah2' );

(Names changed to protect the innocent.)

So I get an error at the blah2 test, (like, not the test failing, but a compile error) and was very confused.

Well, putting parentheses thusly fixed it:
ok( ThatPackage::blah($bar), 'blah2' );

Which is fine and dandy, but makes me somewhat sad because I don't understand why that's necessary just because the stupid string in $bar has leading whitespace. :(

I don't suppose some kind monk could make sense of it for me?

I'm a peripheral visionary... I can see into the future, but just way off to the side.

In reply to Sub calling sadness by nefigah

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.