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

Re^3: Modifying passed-in variables

by Preceptor (Deacon)
on Nov 03, 2015 at 14:49 UTC ( [id://1146816]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Modifying passed-in variables
in thread Modifying passed-in variables

I'm prepared to bet the error you got was: Can't use string ("3") as a SCALAR ref while "strict refs". This is one reason why your function isn't very friendly.

What your function is doing is _expecting_ a reference, then modifying the value referenced. So you can call it by:

foo ( \$data );
Which is passing in a reference, that then "foo" alters. Because otherwise what you're doing is: ${'3'}++ which doesn't make a lot of sense.

Action at a distance like that is generally considered bad form - you don't know what what the subroutine "foo" is doing to your local variable. So normally, what you would expect to pass in a value, and get back a result.

You should probably note - you _do_ get a result back from your subroutine, that's the initial (pre-increment) value of $data. That can be confusing

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2026-02-14 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.