herbert breunung <[email protected]> writes:
> Am 15.07.2010 11:15, schrieb Johan Vromans:
> > Calling subroutines with & is explictly advised
> > against, and with reason.
>
> which reason?
You already hint at parameters... Calling a subroutine with & bypasses
context coercion and also passes the caller's @_ which can lead to
surprising results.
sub foo {
&amIstillalive;
my ($arg) = @_;
print( "arg = $arg\n" );
}
sub amIstillalive {
print( shift() ? "got something " : "" );
}
foo( 24, 25, 26 ); # prints "got something 25"
> in any other case I would say you right, but here are no parameters
> involved
Wrong. You pass the caller's @_ to the subroutine so it possibly
*does* get arguments.
Also, once you start calling some subs with & it could become a
habit to use & for other subroutine calls as well.
You teach Perl, so you know that it is important to use a consistent
approach throughout. Perl trainees will be much confused if you mix
foo() and &foo in your code.
-- Johan