I would state it slightly differently. The function returns nothing different when it is passed no parameters because it takes no parameters — or more precisely, it does nothing with any parameters it may be passed. The array @list_of_numbers is accessed (not declared) within the function. This treats the array as a global variable (even though technically it is lexical). I notice other instances of such access in your functions. Accessing a mutable global (as opposed to a constant) within a function is generally considered a Bad Thing, and is officially Frowned Upon. You have been warned.
Give a man a fish: <%-(-(-(-<
| [reply] [Watch: Dir/Any] [d/l] [select] |
Which is why when I add use strict; it gives me errors? How would I go about making my variables constant rather than mutable global within a function? I would prefer not to be entangled with Bad Things or Frowned Upon.
| [reply] [Watch: Dir/Any] [d/l] |
... when I add use strict; it gives me errors ...
I don't know the current state of your code and so cannot say why it will not compile with use strict; What do the error messages say?
How would I go about making my variables constant rather than mutable global ...
Variables (that actually vary) are good. The point is to use variables that have as narrow a scope as (reasonably) possible. This practice will save you a lot of programming grief. Declaring variables at the top of your program and then accessing them deep within a function is your ticket for a roller-coaster ride to Hell.
Another parenthetic thought: the statements
print above_mean(@list_of_numbers);
or
print above_mean();
from the code above print the value returned by a call to above_mean(), but what does this function actually return? Is it anything useful? (IOW: The function already prints a bunch of stuff during its execution, what's the point of printing its return value, whatever it may be?)
Give a man a fish: <%-(-(-(-<
| [reply] [Watch: Dir/Any] [d/l] [select] |