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

Re^9: Combinations of lists, etc

by AnomalousMonk (Archbishop)
on Oct 08, 2019 at 21:06 UTC ( [id://11107218]=note: print w/replies, xml ) Need Help??


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

"In the first, two different anonymous array references are being constructed. In the second, ..."

So how can we use this concise & convenient "x 2" syntax to generate the former?

I think you understand this already, so I'll answer just for the sake of completeness: You can't. The  x operator (see perlop) makes exact copies either of the elements of a list, the copies of which form another list, or of a string | a scalar, which is a string or stringized "thing" (number, reference, whatever), the copies of which are then contatenated together. And it's not possible to get different things if you're making exact copies of a thing (if you're doing it right).


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

Replies are listed 'Best First'.
Re^10: Combinations of lists, etc
by tel2 (Pilgrim) on Oct 08, 2019 at 22:16 UTC
    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?

      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://11107218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found