Irfan.Sayed@[EMAIL PROTECTED]
asked:
> I have certain doubts.=20
>=20
> What's the meaning of " if
> mysubroutine was defined with prototypes and you were trying=20
> to disable that" sentence.=20
>=20
> Could you please elaborate that what's the meaning of this???
When declaring a subroutine, you can optionally also declare
a prototype for it - i.e. the number and type of arguments.
This allows for a limited sort of compile time parameter
checking aswell as parameter type coercion.
For example:
#!/usr/bin/perl -w
use strict;
sub prototyped ($) {
print "prototyped args: ", join(', ', @[EMAIL PROTECTED]
), "\n";
}
sub unprototyped {
print "unprototyped args: ", join(', ', @[EMAIL PROTECTED]
), "\n";
}
my @[EMAIL PROTECTED]
=3D qw( foo baz bar );
prototyped @[EMAIL PROTECTED]
@[EMAIL PROTECTED]
@[EMAIL PROTECTED]
args: 3
unprototyped args: foo, baz, bar
prototyped args: foo, baz, bar
The first sub is declared with a prototype to expect a scalar value as =
the first argument. This declaration forces the argument @[EMAIL PROTECTED]
into =
scalar context, so that it evaluates to the number of elements in the =
array, i.e. 3.
Without the prototype, the array is passed as an array to the =
subroutine.
If you use the old-style subroutine calling syntax with a prepended &, =
any prototypes for the function are disabled.
Please see the perlsub manpage ("perldoc perlsub") for the
gory details on prototypes and subroutine calling syntax.
HTH,
Thomas


|