Hi all,

I have some code that uses Term::ReadKey to get some user input, but 99 times out of 100 when this script is run, it picks the data up from a file instead, and Term::Readkey isn't needed. So I figure why not do away with the dependency, and require Term::ReadKey in when needed.

But the sub that uses it contains a couple of statements like this:

ReadMode 1; # some stuff ReadMode 2;

Intrigued by this - apparently a function call without parentheses - I asked in the CB, and was told that the parentheses are optional for a single param function call. But this test case:

testcall 1; testcall(2); sub testcall { print $_[0]; print "\n"; }

fails to compile with:

Number found where operator expected at fcall.pl line 1, near "testcal +l 1" (Do you need to predeclare testcall?) syntax error at fcall.pl line 1, near "testcall 1" Execution of fcall.pl aborted due to compilation errors.

(On AS perl, 5.6.1). Term::ReadKey doesn't appear to use prototypes incidentally.

I'm intrigued - is there a functional difference between ReadMode 1; and ReadMode(1); and if so, what? Or am I being really, really dense?

Thanks.

Update: thanks to duff. I'd sort of always assumed that

callsub(); sub callsub{#dostuff}
and
sub callsub(){#dostuff} callsub();
were equivalent, and never encountered anything that proved me wrong. I know better now :-)

--------------------------------------------------------------

"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".

Can you spare 2 minutes to help with my research? If so, please click here


In reply to 'function' calls without parentheses by g0n

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.