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.

Predeclared functions

Predeclared functions - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Predeclared functions

You may have noticed that some built-in fuctions may be called without parentheses. Here's a working copy of Func.pl from Chapter 10 of the exercise files. And down here in our "Function," there on line 10, you see the "Say" function call. So, "Say" is a built-in function, and you notice I do not have parentheses. I could add parentheses, and it'll work just fine. I'll save that and run it. But it's very common, and even more common than with parentheses to see these built-in functions called without parentheses at all. And yet, when I call "Func," if I take the parentheses off of here, I get an error. So, how can I make it so that my functions work like the built-ins? Well, it's actually very easy. I go up here, and I say, "Use subs." And I'll use "Quote word," and "Func, and semicolon." And now, when I run this, it calls function, even though I don't have parentheses. In fact, I can give it parameters. I can say "Foo, bar and baz." And I can display those inside the function, and…

Contents