[EMAIL PROTECTED] wrote: > > Here's an excerpt about the & from orielly and what the heck does it means: > > "...If a subroutine is called using the & form, the argument list is > optional. if ommitted, no @_ array is setup for the routine; the @_ array > at the time of the call is visible to subroutine instead." > > So, is there a better or worse? both ways works for me. I just started > going back and putting the & onto the sub ;) I don't like it the & but I > thought that you need it.
No you don't need it and you shouldn't use it unless you do need it. And if you don't know whether you need it or not then you probably don't need it. perldoc perlsub [snip] A subroutine may be called using an explicit `&' prefix. The `&' is optional in modern Perl, as are parentheses if the subroutine has been predeclared. The `&' is not optional when just naming the subroutine, such as when it's used as an argument to defined() or undef(). Nor is it optional when you want to do an indirect subroutine call with a subroutine name or reference using the `&$sub ref()' or `&{$subref}()' constructs, although the `$sub ref->()' notation solves that problem. See the perlref manpage for more about all that. Subroutines may be called recursively. If a subroutine is called using the `&' form, the argument list is optional, and if omitted, no [EMAIL PROTECTED]' array is set up for the subrou tine: the [EMAIL PROTECTED]' array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid. &foo(1,2,3); # pass three arguments foo(1,2,3); # the same foo(); # pass a null list &foo(); # the same &foo; # foo() get current args, like foo(@_) !! foo; # like foo() IFF sub foo predeclared, else "foo" Not only does the `&' form make the argument list optional, it also disables any prototype checking on argu ments you do provide. This is partly for historical rea sons, and partly for having a convenient way to cheat if you know what you're doing. See the Prototypes manpage below. [snip] Constant Functions Functions with a prototype of `()' are potential candi dates for inlining. If the result after optimization and constant folding is either a constant or a lexically- scoped scalar which has no other references, then it will be used in place of function calls made without `&'. Calls made using `&' are never inlined. (See constant.pm for an easy way to declare most constants.) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]