Difference between &function and function() in perl [duplicate]

It has very specific uses:

  • & tells Perl to ignore the sub's prototype.
  • & can allow you to use the caller's @_. (&foo; with no parens or arguments).
  • goto &foo; and defined &foo.
  • Getting a reference (e.g. \&foo).

Some people (mostly beginners) use it to distinguish user subs from builtin functions, since builtin functions cannot be preceded by &.


As mentioned by @manatwork and @KeithThompson you can find information in these articles:

  1. A general description - What's the difference between calling a function as &foo and foo()?
  2. Subtle information about using & or not for a function call - perlsub: Perl Subroutines: Description.