Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: [Homework Question] Subroutines & References

by AnomalousMonk (Archbishop)
on Feb 11, 2015 at 17:21 UTC ( [id://1116364]=note: print w/replies, xml ) Need Help??


in reply to Re^2: [Homework Question] Subroutines & References
in thread [Homework Question] Subroutines & References

print above_mean(@list_of_numbers);

Just as a matter of curiosity, you might try this variation on the quoted statement:
    print above_mean();
Does calling the  above_mean() function without any parameters make any difference to the value returned by the function? If not, why not?


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^4: [Homework Question] Subroutines & References
by Anonymous Monk on Feb 11, 2015 at 18:57 UTC
    calling above_mean(); function without parameters make does not make any difference to the value returned by the function. I believe this is because @numbers (which I had as the parameter) is already declared inside of my subroutine above_mean - is this accurate?

      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:  <%-(-(-(-<

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1116364]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found