Routine and Subroutine

Updated: 04/26/2017 by Computer Hope

A routine or subroutine also referred to as a function, procedure, and subprogram is a portion of code that may be called and executed anywhere in a program. For example, a routine may be used to save a file or display the time. Instead of writing the code for these commonly performed tasks, routines are made and called when these tasks need to be performed. Below is a basic example of a Perl subroutine.

Subroutine example

&hello;

sub hello {
     print "Hello World!\n";
}

In the above example, a user could call the hello subroutine (in this example, by typing &hello;) anywhere within the program and have the program print Hello World!. After the subroutine has completed the programs goes to the return address, which is directly after &hello; and runs any additional code.

Call, Control flow, DLL, Function, Instance, Programming terms, Return address, Return statement, Sub, Stubroutine