Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Why use references?

by chas (Priest)
on Dec 11, 2005 at 19:04 UTC ( [id://515885]=note: print w/replies, xml ) Need Help??


in reply to Why use references?

Of course, read the docs. However, here's a very short answer.
1. To model muldimensional arrays, (hashes, etc.) An element of an array must be a scalar, so it can't be another array - but it can be a reference to an array.
2. It is usual more economical to pass an array (or hash) reference to a sub (and dereference as needed inside the sub) rather than passing the whole array (or hash.) And when passing several arrays (or hashes) to a sub, they get flattened into a single list and lose their integrity; but you can pass several array or hash references to a sub and then dereference inside the sub.
Of course, the language could have been designed so that references only appear behind the scenes and aren't handled by the user, but then likely a lot of flexibility would have been lost.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2025-02-07 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (94 votes). Check out past polls.