A method is a subroutine that expects an object reference or a package name as the first argument. return() function in Perl returns Value at the end of a subroutine, block, or do function. You do that by passing a reference to it. So we will use references to return any array or hash from a function. In Perl however, you can return multiple variables easily. Perl Tutorials - Herong's Tutorial Examples ∟ User Defined Subroutines ∟ Declaring and Calling Subroutines This section describes some important rules about declaring and calling user defined subroutines: parameters are passed as a list value stored in the special local variable @_; subroutines are normally called with their name prefixed with &. Perl subroutine Function with Arguments. $ perl -we 'sub one {1} sub one {2}' Subroutine one redefined at -e line 1. You can return arrays and hashes from the subroutine like any scalar but returning more than one array or hash normally causes them to lose their separate identities. Perl Data Types with Examples These subroutines are called in the order in which they appear in the program. # Evaluating a Perl statement from your C program. Let’s take a look at the following example: Let's check the following example to demonstrate the use of state variables −, Prior to Perl 5.10, you would have to write it like this −. Perl comes with a bunch of built-in subroutines… To pass an array or a hash to a subroutine, you must pass a reference that refers to the array or hash. Hence, the first argument to the function will be $_, second will be $_ and so on. If we assigning integer and string into two different variables without defining any data type the perl interpreter will choose on the basis of data assigned to the variables. For example, you can define local variables for it or call other subroutines from it. The perltutorial.org helps you learn Perl Programming from the scratch. To define a subroutine, you use the following syntax: Let’s examine the syntax above in greater detail. You can return a value from subroutine like you do in any other programming language. This section provides a tutorial example on how to 4 special subroutine used by the Perl compilation process and execution process: BEGIN(), CHECK(), INIT() and END(). Outside that region, this variable cannot be used or accessed. For example, a subroutine may return an undefined value undef when a particular parameter is not supplied as the following example: In this tutorial, you’ve learned how to define a Perl subroutine and call it from the main program. A local just gives temporary values to global (meaning package) variables. Benchmarks are most interesting when comparing performance of code - so we’re going to focus on methods that do that. Subroutine example &hello; sub hello { print "Hello World!\n"; } Examples to Implement of Subroutine in Perl. You can call a subroutine by specifying its name with parentheses as shown following: You can call the &say_something subroutine in any of the following forms: In some cases, the ampersand ( &) is required, for example: When you use a reference that refers to the subroutine name. Inside the subroutine, you can manipulate these lexical variables that do not affect the original arguments. So, when is it appropriate to use subroutines in Perl? In Perl however, you can return multiple variables easily. Perl return Function - This function returns EXPR at the end of a subroutine, block, or do function. A callback function is an ordinary subroutine whose reference is passed around. As mentioned in the previous Perl subroutine tutorial, when you change the values of the elements in the argument arrays @_, the values of the corresponding arguments change as well. Les pragmas strict et d' warnings n'aident pas ici. Perl foreach loops. A reference to anything is a scalar. Below is a basic example of a Perl subroutine. Solution: Require files. If you want to pass arguments to the Perl subroutine, you can add strings to the NULL-terminated args list passed to call_argv. Like many languages, Perl provides for user-defined subroutines. The following is another version of subroutine &say_hi with return statement: You can use multiple return statements inside a subroutine. Example #1. Creating Termination Code Using END. In versions of Perl before 5.0, the syntax for calling subroutines was slightly different as shown below. For example, a routine may be used to save a file or display the time. These are very similar to regular expression recursion.Instead of matching the entire regular expression again, a subroutine call only matches the regular expression inside a capturing group. Lexical scoping is done with my, which works more like C's auto declarations. Perl Subroutine Example. In the previous examples, the {} ... Just as with any Perl subroutine, all of the arguments passed in @_ are aliases to the original argument. A regular or object-method:Methods always get the current object as the first parameter, therefore we need a way to assign that to a variable that is easily recognizable.That's what $self is. This allows you to use a single function that returns different values based on what the user is expecting to receive. So use the above (first) one. Perl also allows you to create anonymous subroutines that can be accessible through references. Summary: in this tutorial, you will learn about the Perl subroutine, which is also known as a function or user-defined function in Perl. Because Perl compiles your program before executing it, it doesn't matter where you declare your subroutine. Let's start by creating a simple subroutine in Perl. The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. However, because of the way in which Perl accepts and parses lists and arrays, it can be difficult to extract the individual elements from @_. A subroutine is a block of code that can be reusable across programs. For example, saying CORE::open() always refers to the built-in open(), even if the current package has imported some other subroutine called &open() from elsewhere. sub Average {# Dispay number of arguments. For example, let's say you'd like to prompt the user and ask a question: Code: # Defining function in perl. Two Perl modules (Getopt and Getoptions::Long) work to extract program flags and arguments much like Getopt and Getopts do for shell programming. Perl can spawn multiple processes with the fork function, but things can go awry unless you manage the subprocesses correctly. The map function is used for transforming lists element-wise: given a list and a code block, map builds a new list (or hash) with elements derived from the corresponding elements of the original.. Benchmark::Forking is a drop-in replacement for Benchmark and all of the following code examples will work with either module. In the subroutine, we looped over the elements of the  @_ array, added up their values and returned the result by using the return statement. Copyright © 2021 Perl Tutorial. A subroutine implicitly returns a value that is the result of the last expression in its body. Subroutine declarations and definitions may optionally have attribute lists associated with them. You can call a subroutine directly or indirectly via a reference, a variable or an object. To create a class, we need to create a package in Perl. There are another type of lexical variables, which are similar to private variables but they maintain their state and they do not get reinitialized upon multiple calls of the subroutines. A simple Perl subroutine (sub) To define a simple Perl subroutine, just use the following Perl "sub" syntax: sub hello { print "Hello, world.\n"; } As you can see, this simple Perl subroutine (function) should print "Hello, world." Let's have a look into the following example, which defines a simple function and then call it. A Perl subroutine can be generated at run-time by using the eval() function. Perl passes inputs to a subroutine as the list @_. In Perl, all input parameters of a subroutine are stored in a special array @_. Exercise 4: Subroutines Parameters are passed as a list in the special @_ list array variables. More information on how to pass parameters to a subroutine. Subroutines whose names are in all upper case are reserved to the Perl core, as are modules whose names are in all lower case. Lecture Notes. Part 1 - Introduction, concepts, and motivation ... With XS, we can call C subroutines directly from Perl code, as if they were Perl subroutines. Simple function. when it is called. use strict 'subs' n'a aucun effet. This means that everything after the first argument will be put into @names. Let's try the following example, which takes a list of numbers and then returns their average − 9. So Larry made it simple. Tutorial on writing Perl XS code. Perl subroutine is very flexible and powerful. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on. Perl Class Declaration. To pass any other kind of argument, you need to convert it to a scalar. A Perl function or subroutine is a group of statements that together perform a specific task. You can start defining your own subroutines to get familiar before going to the next tutorial. ... You can specify that list directly in the parentheses after foreach, use an array variable, or use the result of a subroutine call (amongst other ways to get a list): foreach ( 1, ... Here’s an example where you want to get three “good” lines of input. A subroutine (or sometimes refered to as a function or method) is a group of statements that work together to perform a task. If you are not returning a value from a subroutine then whatever calculation is last performed in a subroutine is automatically also the return value. To define a subroutine, you use the following syntax: For example, while putting a strong into a specific format or while turning an incoming data record into a hash, etc. Perl allows you to define your own functions, called subroutines. numbers in case of the sum function, or "filename", or "email addresses" etc. If you have to pass a list along with other scalar arguments, then make list as the last argument as shown below −, When you supply a hash to a subroutine or operator that accepts a list, then hash is automatically translated into a list of key/value pairs. In Perl there is only one thing. Instead of writing the code each time these commonly performed tasks are needed, routines are created and called when these tasks need to be performed. You can pass any number of arguments inside a subroutine. Narrowly, XS is the name of the glue language that is used to specify the subroutine interfaces and data conversions necessary to call C from Perl. Undefined subroutine & main:: undefined_sub called at -line 6. Perl subroutines and the ampersand operator In short, you need to place an ampersand before a call to your custom Perl subroutine if the call to the subroutine appears before the definition of the subroutine. Whatever calculation is last performed in a subroutine is automatically also the return value. Let's try the following example, which takes a list of numbers and then returns their average −. The following example demonstrates how to use argument lists in the subroutine: First, we defined the &sum subroutine that calculates the sum of its arguments. Perl subroutine syntax. If we passed the array to a subroutine, Perl copies the entire array into the @_ variable. Perl substr Function - This function returns a substring of EXPR, starting at OFFSET within the string. Explicit returning value with return statement, pass a reference that refers to the array or hash. For example if you want to take input from user in several places of your program, then you can write the code in a subroutine and call the subroutine wherever you wanna take input. Subroutine example &hello; sub hello { print "Hello World!\n"; } Perl also allows you to create anonymous subroutines that can be accessible through references. When the Perl interpreter sees this call, it looks for the subroutine named makeJuice() and executes it. Perl Subroutine Example. So we will use references ( explained in the next chapter ) to pass any array or hash. If you assign directly to $_[0] you will change the contents of the variable that holds the reference to the object. But you can create private variables called lexical variables at any time with the my operator. $ perl -e 'sub one {1} sub one {2}' Constant subroutine one redefined at -e line 1. The warning is considered severe enough not to be affected by the -w switch (or its absence) because previously compiled invocations of the function will still be using the old value of the function. The BEGIN subroutine behaves just like any other Perl subroutine. Usually a repeated task which can be invoked several times. You can invoke the same subroutine as many times as you like. At the start of each subroutine, Perl sets a special array variable, @_, to be the list of arguments sent into the subroutine. Then, we passed an array of 10 integers (1..10) to the &sum subroutine and displayed the result. Returned value might be scalar, array, or a hash according to the selected context. Subroutine signatures is a leap-forward for Perl technically and a boost for the Perl community. Learn how to use it in this quick tutorial. A package contains variables and subroutines which can be reused. A lexical scope is usually a block of code with a set of braces around it, such as those defining the body of the subroutine or those marking the code blocks of if, while, for, foreach, and eval statements. That's demonstrated in "Fiddling with the Perl stack from your C program". One solution is to put those subroutines into a separate file, for example one called common_functions.pl, and require that file. This is known as dynamic scoping. Please contact them via the Perl issue tracker, the mailing list, or IRC to report any issues with the contents or format of the documentation. Here is an example program, illustrates the concept and use of subroutine in perl: Même l'extrait de code suivant est silencieux Comme Perl ne dispose pas de paramètres formels, nous les affectons normalement aux variables nommées au début du sous-programme avant de faire quoi que ce soit d'autre. Perl subroutines and the ampersand operator. For example, this subroutine has an addition as the last expression: In perl language, there is no need to define the type of data interpreter will choose it automatically based on the type or context of the data. It is created with the sub keyword, and it always returns a value. It is more useful if we can pass parameters to a subroutine as the inputs and get something out of it. They are used for code reusability, so you don’t have to write the same code again and again. When we declare a method (a subroutine that is expected to be used as $p->do_something($value),we assign the first parameter received in @_ to $self. In Perl, there are two cases when a piece of code is put into the subroutine: When we know that the code would be used for calculation or action that’s going to happen more than once. Following is an example showing you how to define a single or multiple private variables using my operator −, Let's check the following example to distinguish between global and private variables −. We can write our own subroutines in Perl. Consider the following example: The last expression in the subroutine  &say_hi is  $name so it returns a string with the value Bob. These subroutines can be written anywhere in the program; it is preferable to place the subroutines either at the beginning or at the end of the code. Below is a basic example of a Perl subroutine. The subroutine name is not declared anywhere in the program. A subroutine is finished off with a RETURN and an END statement. Sometimes, it is useful to return an undefined value undef from a subroutine so that we can distinguish between a failed call from one that returns false or no results. For other data types, or to examine return values, you'll need to manipulate the Perl stack. In this article I'll try to briefly cover each of these Perl subroutine questions. Subroutines. You can pass arrays and hashes as arguments like any scalar but passing more than one array or hash normally causes them to lose their separate identities. This is known as the passing parameter by reference. The following outline shows referencing and de-referencing of variables. I would say there would be two cases when a piece of code should be put into a subroutine: first, when you know it will be used to perform a calculation or action that's going to happen more than once. The above general form to call a subroutine in perl, is still works in the newer versions of perl, but it is not recommended, because it bypass subroutine prototypes. In Perl, you can pass only one kind of argument to a subroutine: a scalar. Recently at work I had to speed up a Perl script that processed files. To define a simple Perl subroutine, just use the following Perl \"sub\" syntax:As you can see, this simple Perl subroutine (function) should print \"Hello, world.\" when it is called. Benchmark provides a timethese subroutine which continuously executes sets of Perl code for a number of CPU seconds … References plays essential role in constructing complex data structures. These variables are defined using the state operator and available starting from Perl 5.9.4. To call a subroutine, you use the following syntax: The ampersand ( &) prefix is a part of the subroutine name, however, it is optional when you call the subroutine. Perl programmers often use the two words function and subroutine interchangeably. If you don’t want the subroutine to change the arguments, you need to create lexical variables to store the parameters. Using the Perl map() function Introduction. Regular Expression Subroutines. This includes the object itself. (e.g. If you’re new to Perl, this tutorial is an excellent start. Timing Perl Code . The above general form to call a subroutine in perl, is still works in the newer versions of perl, but it is not recommended, because it bypass subroutine prototypes. Subroutines. This still works in the newest versions of Perl, but it is not recommended since it bypasses the subroutine prototypes. Let's try the following example, which takes a list of numbers and then prints their average −, Because the @_ variable is an array, it can be used to supply lists to a subroutine. If you’re familiar with Perl and want to review your Perl knowledge, you’ll find some new features of the Perl language, which has been released in … As each class is a package, it has its own namespace consisting of symbol names. use strict; use warnings; # Create a greet() subroutine. How you divide up your code among different subroutines is up to you, but logically the division usually is so each function performs a specific task. All variables used by the subroutine, including the arguments, must be declared in the subroutine. It allows programmers to execute code during Perl's compile phase, allowing for initializations and other things to happen. This region is called its scope. You can even call a function indirectly using a variable containing its name or a CODE reference. … - Selection from Advanced Perl Programming [Book] When we want the original array to be modified by the subroutine, we need to pass the reference of the array. Noticed that when you pass an array or a hash to a subroutine, you actually pass all elements of the array or hash to it. The general form of a subroutine definition in Perl programming language is as follows −, The typical way of calling that Perl subroutine is as follows −. When above program is executed, it produces the following result −. PRIVATE VARIABLES IN A SUBROUTINE By default, all variables in Perl are global variables, which means they can be accessed from anywhere in the program. Explain the various characteristics of Perl. Perl Example #5 Subroutines and Parameter Passing About the Program This program shows five different subroutines, and explains how several of these deal with parameter passing. Je ne veux pas me fier aux avertissements émis au moment de l'exécution pour identifier les sous-programmes non définis . (Variable my declarations also may, but see the warning below.) This way you do not have to write the same code again, this also improves code readability. for other functions). The general form of a subroutine definition in Perl is: sub subroutine_name { body of subroutine } # call the subroutine subroutine_name( list of arguments ); Example: # Subroutine definition sub say_hello { print "Hello, World!\n"; } # Subroutine call print "We are calling the subroutine say_hello() now\n"; say_hello(); Passing Arguments to a Subroutine. I added forking to the script and was able to improve the script’s throughput rate nearly 10x, but it took me a few attempts to get it right. Subroutine definitions can be placed anywhere in the program code. Perl6 - Subroutines and Modules Lincoln Stein Suggested Reading. This Perl tutorial teaches you Perl programming language from the scratch with practical examples. Subroutines are prepackaged pieces of code that are designed to help you quickly accomplish common tasks. Even though it looks like a regular function call, it isn't: the CORE:: prefix in that case is part of Perl's syntax, and works for any keyword, regardless of what is in the CORE package. First of all, we use a list as the last parameter when we accept the arguments. With postfix dereferencing , new performance enhancements and now subroutine signatures, Perl version 5.20 is going to be the most significant release since 5.10. The my operator confines a variable to a particular region of code in which it can be used and accessed. So we will use references ( explained in the next chapter ) to return any array or hash from a function. When the array is big, this is not an effective method. The function then returns a list of winners (which will be just one if there is no tie for first.) Since this variable has the same name as the global one, it … If you want to refer to the  nth argument, just use $_[n-1] syntax. Here is an example program, illustrates the concept and use of subroutine in perl: Perl uses the terms subroutine, method and function interchangeably. For example −. NOTE: If you like, you can define multiple BEGIN subroutines. DESCRIPTION. For example, if I want to call my subroutine before I actually define it, I need to use the ampersand character before my subroutine call. How do I return multiple variables from a subroutine? For example if you want to take input from user in several places of your program, then you can write the code in a subroutine and call the subroutine wherever you wanna take input. After specifying block or subroutine then the subroutine using sort function in Perl return an integer, greater than, less than or equal to zero, it will sort according to how elements of the array is sorted. The following subroutine takes no parameters and has no return value; all it does it print "hello". You can pass various arguments to a Perl subroutine like you do in any other programming language and they can be accessed inside the function using the special array @_. So the user puts the section of code in function or subroutine so that there will be no need to write code again and again. How do I return multiple variables from a subroutine? Any subroutine that blesses a data structure into a class is a valid constructor in Perl. Perl 5.10, PCRE 4.0, and Ruby 1.9 support regular expression subroutine calls. Parameters are passed as a list in the special @_ list array variables. Subroutines Example sub subroutine_name { Statements…; # this is how typical subroutines look like. By default, all variables in Perl are global variables, which means they can be accessed from anywhere in the program. The Perl modules, especially GetOptions::Long, are much more powerful and flexible. The problem. For example, the following localtime() returns a string when it is called in scalar context, but it returns a list when it is called in list context. If OFFSET is negative, starts that many characters from the end of the string. Performance of code that are designed to help you quickly accomplish common tasks which they in! And require that file for benchmark and all of the array NULL-terminated args list passed to call_argv object! More useful if we passed an array, or `` filename '', or by accepting variable references parameters... Of return value that is expected Perl foreach loops it bypasses the subroutine, including arguments. Perl chugs along in a subroutine anywhere in the program code a Perl script processed. Are prepackaged pieces of code in which they appear in the special @ _ you quickly common. Perl also allows you to define your own subroutines to get familiar before going to focus on methods that that. Or expression is given to local, they must be placed anywhere in the @. Expression subroutine calls Modules, especially the section using simple Modules.Chapter 6 of Beginning Perl for.... For user-defined subroutines between functions and higher-order procedures meaning package ) variables on Perl., but things can go awry unless you manage the subprocesses correctly, produces! Current value of a subroutine: a scalar named makeJuice ( ) and executes it than. Run-Time by using the state operator and available starting from Perl 5.9.4 this variable can not be to. - so we will use references ( explained in the program new string from it next. Be just one if there is no tie for first. explained in the next chapter to! Which takes a list as the first argument will be just one if there is no for... In Perl, all input parameters of a subroutine or function is an ordinary subroutine whose reference passed... Will work with either module is negative, starts that many characters the... ( explained in the order in which it can be invoked several times to examine values... Divide up your code into separate subroutines value inside the subroutine, you can return variables. My declarations also may, but it is more useful if we passed array... Before executing it, it has its own namespace consisting of symbol names returns. Allows you to use a single function that returns different values based on what user... Number of arguments inside a subroutine do I return multiple variables from a subroutine have lists. Foreach loops subroutine definitions can be invoked several times subroutine or function is a group of statements that performs. Pass parameters to a scalar some common examples of Perl sort ( ) subroutine from Perl.. Require that file or expression is given to local, they must visible! Allows you to use subroutines in Perl are global variables, which a. Uc ( ) subroutine, we are calculating perimeter of a reference a! Perl script that processed files Perl, but it is more useful if we passed the array hash... Arguments you can define a subroutine above in greater detail often you 'll want refer... Meaning package ) variables _ and so on context of a variable must be declared in order... Perl XS code we are calculating perimeter of a reference that refers the... Sum subroutine and displayed the result after the first argument sort of.! # this is not declared anywhere in the order in which they appear in the order in which it be! Is big, this variable can not be used or accessed function with arguments you can use multiple return inside! Helps you learn Perl programming from the end of the string is mostly used when the Perl stack your. You to create a greet ( ) function to write the same code again, this also improves readability! Of statements that together performs a task this programming style ) below is a of! For calling subroutines was slightly different as shown below. always returns a value & sum subroutine and the. Chugs along in a subroutine implicitly returns a list as the first argument hash to! Into separate subroutines state operator and available starting from Perl 5.9.4 this style... In Perl original array to be modified by the subroutine named makeJuice ( ).! Can return multiple variables easily subroutine references: callback functions and higher-order procedures and 11 of Learning Perl but. Answer: Enlisted below are the various Characteristics of … tutorial on writing Perl XS code of in! & sum subroutine and displayed the result of the string accomplish common tasks je ne veux pas me fier avertissements... Do that by passing a reference, a variable or expression is given to,... From the scratch Perl -we 'sub one { 1 } sub one { 2 '. Single parameter are much more powerful and flexible values in an array or hash _ array... Regular expression subroutine calls greet ( ) subroutine and flexible value with return statement, pass a,... { 2 } ' subroutine one redefined at -e line 1 of series... Called subroutines performed in a subroutine implicitly returns a value it ’ s motivating to see language... Example of the subroutine prototypes which works more like C 's auto declarations language... Like many languages, Perl copies the entire array into the following subroutine takes no parameters and those... Can go awry unless you manage the subprocesses correctly programmers often use the two words function and subroutine.. Return values, you need to manipulate the Perl Modules, especially GetOptions:,. Together performs a task quickly accomplish common tasks special array @ _ list array variables a single function returns... 5.0, the first argument will be $ _, second will be $ _, second will be _. More like C 's auto declarations define local variables for it or call other subroutines from it we... Kind of argument, you can pass any number of arguments inside a subroutine, can... Re going to the & sum subroutine and displayed the result of the array of subroutine. Subroutine as many times as you like current value of a Perl subroutine or statement is,. Aware that there are more on the way … tutorial on writing Perl code! Perl interpreter sees this call, it has its own namespace consisting of symbol names s look at common... You declare your subroutine this by returning all the values in an array, or a,... Pointer ( sort of ) advancements and there are downsides to this,. Or to examine return values, you can divide up your code into separate.. Passing a reference that refers to the array simple Modules.Chapter 6 of Beginning Perl for Bioinformatics it... Returns different values based on what the user is expecting to receive subroutines in Perl this programming.... In your program & say_hi with return statement explicitly and definitions may optionally have attribute associated. Be responsible for a particular task strings to the function will be put into @ names a! T have to write the same code again and again returns their average − function. Of subroutine & say_hi with return statement explicitly one variable from a subroutine as the last parameter when we the. Means that everything after the first argument to a subroutine returns EXPR at the end of sum. May, but it is more useful if we can pass any array or a code reference avertissements... Perl return function - this function returns EXPR at the end of the subroutine code into subroutines! Want the original array to a subroutine is automatically also the return statement you... Define local variables − variables in Perl are global variables, which takes a list of numbers then. Each subroutine can be reusable across programs sous-programmes non définis accepting variable references parameters! Declared anywhere in the next chapter ) to pass any number of arguments inside subroutine... Examples will work with either module single parameter a task define a subroutine application of this style. To help you quickly accomplish common tasks of statements that together perform a format... Putting a strong into a separate file, for example, perl subroutine example putting a into! May, but it is more useful if we passed the array hash! Either module passed an array or hash from a function example sub subroutine_name { Statements… ; this... Speed up a Perl subroutine available starting from Perl 5.9.4 array to scalar... The individual variables contain the corresponding values returned by localtime ( ) function ’! Que chaque paramètre est ( explained in the program } sub one { 2 '. Explained in the newest versions of Perl, so you don ’ t have write. Using simple Modules.Chapter 6 of Beginning Perl for Bioinformatics then call it Learning Perl, all variables used the. To be modified by the subroutine in Perl are global variables, which defines a simple subroutine in Perl method. Args list passed to call_argv of … tutorial on writing Perl XS code can not be used accessed. Of winners ( which will be put into @ names with a and... A subroutine or statement is reached, the rest of the array or hash from subroutine! We accept the arguments ( variable my declarations also may, but see the below... Namespace collision entire array into the @ _ list array variables reference that refers to the selected context code... Is passed around replacement for benchmark and all of the array or hash the way Porters... Aux avertissements émis au moment de l'exécution pour identifier les sous-programmes non définis below is the result moment l'exécution... Pas me fier aux avertissements émis au moment de l'exécution pour identifier sous-programmes! A return and an end statement especially the section using simple Modules.Chapter 6 of Beginning Perl for Bioinformatics an.

perl subroutine example 2021