Function Parameters

Learn about Perl's parameter handling.

The array of function parameters

A function receives its parameters in a single array, @_. Perl flattens all provided arguments into a single list when we invoke a function. The function must either unpack its parameters into variables or operate on @_ directly:

Press + to interact
sub greet_one {
my ($name) = @_;
say "Hello, $name!";
}
sub greet_all {
say "Hello, $_!" for @_;
}
greet_one('Sam', 'Ash');
greet_all('Sam', 'Ash');

Operations on function

...
Access this course and 1400+ top-rated courses and projects.