Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Why does Perl allow you to return array references to variables in local scope?

by BrowserUk (Pope)
on Oct 16, 2013 at 12:34 UTC ( #1058434=note: print w/replies, xml ) Need Help??

in reply to Why does Perl allow you to return array references to variables in local scope?

I think the easiest way to think of it is that: names have scope; data lives as long as it is referenced.

So whilst the name @arr has gone out of scope; the data that it labeled whilst in-scope, continues to persist, because a reference to it was returned to the caller.

Hence, if you call DoSomething() in a void context - ie. you don't assign the return reference to a name in the calling scope -- then the returned reference will be discarded, and the data it references -- formerly known as @arr -- will no longer be referenced and so will be returned to the process memory pool for reallocation.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2016-10-24 04:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.