Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^6: [Homework Question] Subroutines & References

by Hayest (Acolyte)
on Feb 11, 2015 at 19:48 UTC ( [id://1116381]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^7: [Homework Question] Subroutines & References
by AnomalousMonk (Archbishop) on Feb 11, 2015 at 20:38 UTC
    ... 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:  <%-(-(-(-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found