Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-12-16 21:08 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (459 votes). Check out past polls.