From the course: Perl 5 Essential Training
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Function references - Perl Tutorial
From the course: Perl 5 Essential Training
Function references
- [Voiceover] Perl also supports function references which may not be as common as array or hash references but they can be useful for a number of purposes. Here's a working copy of func.ref.pl from Chapter 11 of the Exercise Files. And you notice that I have a function that I've defined down here, starting on Line 10, and here on Line 7, I'm taking a reference to that function, and so there's the name of the function, and this ampersand indicates that that symbol is a function symbol, just like the percent sign indicates a hash or the at sign indicates an array. And then I take the reference with the reference operator and I assign it to the reference scaler. And now I call it, again I'm using that ampersand, and the curly braces are around the reference itself. And the parentheses, which is the function call operator. And so when I run this, you see I get the result, "This is the excellent function." So it's calling the function through the reference. Okay, so that much probably…
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.