Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: defining variables using my - subroutines

by kennethk (Abbot)
on Sep 05, 2012 at 17:34 UTC ( #991898=note: print w/ replies, xml ) Need Help??


in reply to Re^2: defining variables using my - subroutines
in thread defining variables using my - subroutines

Under normal usage, they take values not variables. If you run the code

sub add_one { my $x = shift; $x += 1; return $x; }
You would not expect the variable you passed in (my $y = add_one($outer_x);) to change value, right? This is a little awkward/contrived, but this is in contrast to more object-oriented frameworks.

Advanced: Of course Perl actually does pass by reference with lvalues bound to @_. But that's probably the best reason for transferring subroutine inputs to locally-scoped variables.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re^3: defining variables using my - subroutines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-08-04 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (59 votes), past polls