in reply to Re^4: Automatic vivification of an object
in thread Automatic vivification of an object
a $ prototype forces scalar context
DB<108> sub nopro { print @_ } DB<109> sub pro ($) { print @_ } DB<110> @a=3..7 => (3 .. 7) DB<111> nopro(@a) 34567 DB<112> pro(@a) 5
This is especially dangerous if your argument is another function call.
Giving a method a prototype other than ($;@) is at best misleading and will result in awfully ugly bugs if someone is assuming:
> $obj->method(...) and class::method($obj,...) (assuming $obj is of type class) are functionally identical
DB<113> sub meth ($$) { print @_ } DB<114> main->meth(@a) main34567 DB<115> main::meth('main',@a) main5
if you want a good self documentation, expand arguments to meaningful names:
sub meth { my ($self, $x_ax, $y_ax, $arr_ref, @opt) = @_; }
I'm not sure what your understanding of "type" is in Perl's context.
|
|---|