g0n has asked for the wisdom of the Perl Monks concerning the following question:
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
andcallsub(); sub callsub{#dostuff}
were equivalent, and never encountered anything that proved me wrong. I know better now :-)sub callsub(){#dostuff} callsub();
--------------------------------------------------------------
"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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 'function' calls without parentheses
by duff (Parson) on Mar 21, 2006 at 16:43 UTC | |
|
Re: 'function' calls without parentheses
by McDarren (Abbot) on Mar 21, 2006 at 16:50 UTC | |
|
Re: 'function' calls without parentheses (link)
by tye (Sage) on Mar 21, 2006 at 16:47 UTC | |
|
Re: 'function' calls without parentheses
by Errto (Vicar) on Mar 21, 2006 at 21:45 UTC |