in reply to Re^2: Pass By Reference Inner Workings - Magic scalar operator
in thread Pass By Reference Inner Workings - Magic scalar operator

First thing's first; diotalevi is right, my %x = %{shift()}; is by far the preferred method. I pulled out the unary + as a prefix that served a similar purpose to your use of scalar in this situation. But it's ultimately a bad example, and shift() is the proper way to do things. Treat a function like a function, (ie, use parens) rather than using the unary plus +.

Now to answer your question: Yes, my %x = %{shift()}; makes a copy of the contents of the hash to a lexical variable. This does cost performance and memory. But there are times when you need a copy, and other times where it's fine to just work with the reference to the original hash, held in $_[0].


Dave