Tutorial by Examples

Subroutines are created by using the keyword sub followed by an identifier and a code block enclosed in braces. You can access the arguments by using the special variable @_, which contains all arguments as an array. sub function_name { my ($arg1, $arg2, @more_args) = @_; # ... } Sin...
Subroutine arguments in Perl are passed by reference, unless they are in the signature. This means that the members of the @_ array inside the sub are just aliases to the actual arguments. In the following example, $text in the main program is left modified after the subroutine call because $_[0] in...
Subroutines hold code. Unless specified otherwise, they are globally defined. # Functions do not (have to) specify their argument list sub returns_one { # Functions return the value of the last expression by default # The return keyword here is unnecessary, but helps readability. return 1...

Page 1 of 1