I´m newbie in perl and I need to define a subroutine in perl, but I don't understand the difference between subroutine and function.
When should I use any of them and how can I send parameters?
I´m newbie in perl and I need to define a subroutine in perl, but I don't understand the difference between subroutine and function.
When should I use any of them and how can I send parameters?
In the documentation, "function" refers to list operators (e.g. chr, print), named unary operators (e.g. chdir) and named nullary operators (e.g. time). These are sometimes called "builtin functions" to avoid ambiguity (though there are builtin subroutines too, such as utf8::upgrade).
In practice, "function" is commonly used to refer to both builtin functions and anything declared with sub.
Arguments are usually passed to subroutine as follows:
foo($x, $y)
Operators don't technically have parameters; they have operands. Most operators that qualify as functions resemble subroutines. perlfunc documents how to use each one.
There isn't a real difference. "Subroutine" is just a name for a function that you write, as opposed to one of Perl's builtin functions. It's okay to call them functions too.
perldoc perlglossary says "If the subroutine returns a meaningful value, it is also called a function," but this doesn't jive with common usage (or even the rest of the docs; not everything in perlfunc returns a value). It seems like function and subroutine are used interchangeably now.