Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^10: Combinations of lists, etc

by tel2 (Pilgrim)
on Oct 08, 2019 at 22:16 UTC ( [id://11107222]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Combinations of lists, etc
in thread Combinations of lists to a hash

Well said, LanX.

So would it be true to say that when taking such "exact" copies of a string, you can modify the copy without affecting the original, but this is not the case when taking such "exact" copies of things like hash keys & values, because the copy will be some kind of reference to the original?

Replies are listed 'Best First'.
Re^11: Combinations of lists, etc
by AnomalousMonk (Archbishop) on Oct 08, 2019 at 22:41 UTC
    Well said, LanX.

    Well, it wasn't LanX, but...

    ... when taking such "exact" copies of a string, you can modify the copy without affecting the original ...

    Yes, because in the case of x, scalars (e.g., strings) are copied (and concatenated) by value, so the copy is independent.

    ... this is not the case when taking such "exact" copies of things like hash keys ...

    Hash keys are strings (scalars).

    ... & values, because the copy will be some kind of reference to the original?

    The value of a hash key/value pair (or item of an array (update: or list)) is always a scalar. A scalar can be a reference. (A reference is always a scalar.) Operator  x copies things exactly, but two or however many exact copies of a given reference always point to a single thing: the "referent". A referent may be referenced by any number of references. (Update: See reference, perlref, perlreftut, and perldsc.)


    Give a man a fish:  <%-{-{-{-<

      OK, thanks again AnomalousMonk, and sorry for renaming you to LanX.  (Where's the "unrename" function when I need it?)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-26 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found