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.
Function arguments - Perl Tutorial
From the course: Perl 5 Essential Training
Function arguments
- [Voiceover] The default array variable is used to pass arguments to a function. Here's a working copy of deffunc.pl, from chapter seven of the exercise files, and you'll notice we have a function call, and we're passing it three arguments. The strings one, two, and three, and there's the function defined, and you notice that it uses this save for each, and @_ that is the default array variable. It's like the default scalar variable, only it's for arrays, so when I run this, you notice it displays. This is func1, and then one, two, and three. Which are the elements in that array, so this function call has passed this array into the function. This default array just happens automatically, you don't need to do anything to initialize it, Perl does that for you, so if you wanna use those values in scalar variables inside of your function, and that's a very common thing to do. You can do something like this, and when I run that, you see it says, one two three, down at the bottom, so it is…
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.