next up previous contents index
Next: Variable scoping Up: Subroutines, functions, and modules Previous: Subroutines, functions, and modules   Contents   Index

Defining subroutines

Subroutines can be declared as
  sub whatever_name {
     do stuff here;
and then called in your program by whatever_name you called it. Naming a subroutine follows the same convention as that for variables - it must start with a letter (upper or lower case) or the underscore _, and then be followed by a combination of letters, numbers, or the underscore. As an example,
  sub welcome {
    print qq{Hello from down under!};
It is customary to put all subroutine definitions either at the beginning or at the end of your script - we will generally put them at the end.