From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding functions

Understanding functions - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Understanding functions

- [Voiceover] Like most languages, Perl provides support for user-defined functions. In some languages, there's a distinction between functions and subroutines where functions return value, and subroutines do not. Perl does not make this distinction. The official Perl documentation uses both words, subroutine and function, interchangeably and without explanation. For my purposes, I prefer the word function. I rarely use the word subroutine. In Perl, a function is defined with the keyword "sub," followed by the name of the function, and a block of code in curly brackets. Perameters are passed in the special default array variable. Like the default scaler variable, the name of the defaul array variable is an underscore character preceded by the at symbol, which makes it an array. The built in shift function is commonly used to access function parameters. It uses the default array variable if an array is not specified. To return a value from a function, use the return statement. The…

Contents