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.
Returning values - Perl Tutorial
From the course: Perl 5 Essential Training
Returning values
- Return values are very simple in Perl. You may return zero or more scalar values as a list. Here's a working copy of func.pl from Chapter 10 of the exercise files and what I'm going to do here, is I'm going to take away this say and I'm going to replace it with a return. So instead of displaying the string from inside of the function, I'm just going to display it from outside of the function, I'm going to put the say here. So the return value of the function is being passed to say and you'll notice when I run it, it does exactly the same thing, it displays its value but it's working differently. Now it's returning the scalar variable with the string in it and it's passing that to say outside of the function. So this is very simply how you return a value. Now if you want to, you can return more than one value. You can return a list, and then I can just say foreach, like that, it'll pass that list to foreach and call say for each value in the list. When I run this, it says one, two…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.