in message <20030119232156.GF1832_at_unixcab.org>,
wrote Mikhael Goikhman thusly...
>
> On 19 Jan 2003 23:11:22 +0000, Mikhael Goikhman wrote:
> >
> > On 19 Jan 2003 15:59:18 -0500, parv wrote:
> > >
> > > > > as a side note, why are you calling the non referenced named subs
> > > > > via "&", e.g. "&showTab($tId, $tabNo);"? won't the named subs
> > > > > will just work w/o "&", am i missing something?
> > > >
> > > > Both are valid Perl syntax. The '&' just means the subroutine
> > > > doesn't have to be declared before it is used. I probably don't
> > > > need it, but using '&' everywhere means I don't even have to worry
> > > > about whether I should use it or not.
> > >
> > > unless you are using non-parenthesis version of subs, it really does
> > > not matter where you declare/define subs.
> >
> > No, this is incorrect. Starting with perl-5.6.0, if you define a function
> > with parameters (and for the fvwm's perllib such definition is a rule),
> > the function should be declared before its first usage,
> > otherwise you get a warning.
oops, yes you are correct.
let me elaborate on ampersand usage in function calls...
perl really doesn't have parameters -- unlike C++, C, Rexx, etc. --
just the TYPE CHECKING of arguments as long as it is NOT BYPASSED.
as soon as function name (during calling it) is prefixed w/ '&', the
type checking just becomes useless decoration. observe...
#!perl -w
use strict;
# function accepts only one scalar argument
# unless name is preceded by '&'
sub print_one($)
{ print $_[0] || 'undef'; }
# normal call, no surprise
print_one('blah');
# no parameter is passed, yet perl doesn't complain
&print_one();
# no parameter is passed, program will abort
#print_one();
# array will be passed but scalar is expected
# since prototype checking is bypassed, doesn't matter
my _at_array = (2,3);
&print_one(_at_array);
# another blow up
print_one(_at_array);
...so if somebody happen to omit an argument, pass wrong kind or
number of argument, no errors will be generated if function is
called w/ '&'. i suppose one would have been expecting errors in
such cases (unless bypassing the prototype check was intentional, of
course).
curious... could it be that perl prototypes are being used for the
wrong kind of reasons (as fvwm perllib requirement)?
> I didn't mean '&' should be used everywhere, I would prefer
> a predeclaration. There is though one case when I prefer the '&'
> syntax - recursive functions.
why for recursive functions? also see above.
- parv
--
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_fvwm.org.
To report problems, send mail to fvwm-owner_at_fvwm.org.
Received on Sun Jan 19 2003 - 19:38:43 GMT